Page 1 of 1

If specific file exists, attrstamp folder

Posted: 21 Oct 2018 18:49
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.

Re: If specific file exists, attrstamp folder

Posted: 21 Oct 2018 19:14
by highend
quicksearch() can easily get all parent folders for directories that contain this file...

Re: If specific file exists, attrstamp folder

Posted: 21 Oct 2018 19:38
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
	}

Re: If specific file exists, attrstamp folder

Posted: 21 Oct 2018 21:18
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

Re: If specific file exists, attrstamp folder

Posted: 21 Oct 2018 22:20
by klownboy
Sorry I messed up the SC exists syntax. I should have tested it, but I'm glad you got it working. :tup: