Page 1 of 1

any option to find or filter out files by path ONLY

Posted: 10 Jun 2012 17:27
by abc550
Hi,

I can not find the right approach to find and/or filter out only files, which contents the search string in the full path (folder or its parent etc. folders), but not in the filename itself. Say, I need to see all files, which are located in any folder, which name includes number "12345" - but except those files, which name itself conclude the part "12345".

My first idea was to use bulean search with the search option "Path" enabled and add a condition to exclude files with "12345" in the name. But actually it is nor possible to exclude only files this way.

Or if is not possible to search files by this criteria, may be I can filter them out in the found files list.

Thanks in advance!

Re: any option to find or filter out files by path ONLY

Posted: 10 Jun 2012 18:27
by highend
I didn't check if it's possible with the normal search function but you could write a script to do what you want.

folderreport(), strpos()/gettoken() and a regexreplace() compare in a foreach loop would be needed to accomplish this.

Re: any option to find or filter out files by path ONLY

Posted: 10 Jun 2012 19:31
by abc550
Thank you, highend!

I'll try you solution. However as I'm not very comfortable with scripts, I'd prefer a "normal search" solution... if it is possible...

Re: any option to find or filter out files by path ONLY

Posted: 10 Jun 2012 23:01
by highend
This should work:

Code: Select all

// Find files where the foldername contains something that the filename
// does not contain

	$input = input("Enter what a folder name must contain:");
	$list = folderreport("files", "r", , "r");
	$output = "";
	foreach($item, $list, "<crlf>") {
		$splitLeft = strpos($item, "\", -1);
		$leftString = substr($item, 0, $splitLeft);
		$rightString = substr($item, $splitLeft +1);
		$resultLeft = strpos($leftString, $input);
		$resultRight = strpos($rightString, $input);
		if($resultLeft != -1 && $resultRight == -1) {
			$output = $output . $item . <crlf>;
		}
	}
	if($output != "") {
		text $output;
	} else {
		msg "No files found!";
	}
It scans for all files recursively in the current directory.