If specific file exists, attrstamp folder

Discuss and share scripts and script files...
Post Reply
JLoftus
Posts: 595
Joined: 22 Jan 2014 14:58

If specific file exists, attrstamp folder

Post by JLoftus »

I have a seemingly simple task I need help with:

in a folder containing thousands of subfolders, I would like to attrstamp each folder ONLY if that folder contains a specific file (desktop.ini)

Seems like a foreach loop with the attrstamp statement in the loop is all I need, but not sure how to walk each child in the tree looking for desktop.ini

Any help greatly appreciated.

highend
Posts: 14940
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: If specific file exists, attrstamp folder

Post by highend »

quicksearch() can easily get all parent folders for directories that contain this file...
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: If specific file exists, attrstamp folder

Post by klownboy »

I just noticed highend suggested faster way using quicksearch, but this should work as well.

Code: Select all

	$folders = listfolder(<curpath>, ,2, <crlf>);    //select the parent folder for all those subs
	foreach($folder, $folders,<crlf>, "e") {
	  if(exists($folder, "desktop.ini") == "1") { //corrected should be: if(exists($folder . "\desktop.ini") == "1") {
	  attrstamp(r, 1, $folder, <crlf>);}  // not sure what attribute stamp you desired
	}
Last edited by klownboy on 21 Oct 2018 22:27, edited 1 time in total.

JLoftus
Posts: 595
Joined: 22 Jan 2014 14:58

Re: If specific file exists, attrstamp folder

Post by JLoftus »

Thanks! That didn't quite work for me, but with this minor tweak, it did:

$folders = listfolder(<curpath>, ,2, <crlf>); //select the parent folder for all those subs
foreach($folder, $folders,<crlf>, "e") {
if(exists($folder . "\\desktop.ini") == "1") {
attrstamp("rs", , $folder);
}
}

Seems the exists function was failing without the concatenation.

Thank you again, very much

klownboy
Posts: 4459
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.8037 at 100% 2560x1440

Re: If specific file exists, attrstamp folder

Post by klownboy »

Sorry I messed up the SC exists syntax. I should have tested it, but I'm glad you got it working. :tup:

Post Reply