Page 1 of 2

How to search in all direct subfolders ie. NOT recursively ?

Posted: 26 Oct 2011 13:13
by Reve_Etrange
Ladies & Gentlemen,

Topic title says it all. I have a (pretty big) 'music' drive, sorted by genres, and sometimes I don't remember where I put a given artist (was it 'electro', 'nu jazz', 'lounge' etc.).
I don't want to waste time running a recursive search, since all artists have their own folder directly under their genre.
I tried something like:

Code: Select all

*\?Air /
from the music drive, or even

Code: Select all

?*\Air /
but none worked.
Is it possible?

Re: How to search in all direct subfolders ie. NOT recursive

Posted: 26 Oct 2011 16:04
by tiago
Once I tried to deal with such a problem trying to determine a pattern so all files matching it would be excluded from results. Then I stumbled upon the limitations of formatlist not being able to report duplicated entries and other I can't recall and I have quit.

Since then XYplorer has being given more resources I may be able to deal with, folderreport among them.

I made something to shorten paths for various tasks and those may give me a clue.

I'll try to think about it and report if I come up with something.

Re: How to search in all direct subfolders ie. NOT recursive

Posted: 26 Oct 2011 16:16
by Jerry
I usually have at least 10 TB of files on 10 separate drives attached and -- not to keep plugging this 3rd party utility -- but I would just enter "Air" into the search field of my Everything.exe window and the results would appear nearly instantaneously, with matching folders listed before files. A double-click on the sought after folder takes me right into XYplorer.

Re: How to search in all direct subfolders ie. NOT recursive

Posted: 26 Oct 2011 16:38
by tiago
Can't say for him but external apps won't save the day for me as usually I have to do a search then do any XY scripting on search results' list.
In case of 3rd party solution for this I pick Instant File Find, has some native actions like "copy whole file path", refine mode and a really small cache to rely on, not for content search.

Re: How to search in all direct subfolders ie. NOT recursive

Posted: 26 Oct 2011 16:59
by Stefan
Reve_Etrange wrote:
How to search in all direct subfolders ie. NOT recursively ?

Is it possible?
I am not really used to this, but maybe the help will aid you?

XYplorer help > Main Topics > Address Bar > Doing "Quick Searches" via the Address Bar

EDIT
I think just ?Air / should work?

Re: How to search in all direct subfolders ie. NOT recursive

Posted: 26 Oct 2011 17:25
by Jerry
I think he actually needs to recurse but not more than 1 level down in each subfolder. So he's at the root of his music drive with say, 10 different Genre subfolders, each containing multiple Artist subfolders. He wants to match no further down than the Artist subfolders directly under each Genre subfolder. (I have this same hierarchy myself, replicated on multiple attached drives.)

Re: How to search in all direct subfolders ie. NOT recursive

Posted: 26 Oct 2011 17:39
by Stefan
Ah, i see, it seams you are right.

Code: Select all

X:\GenreA
        \SubLevel 1
        \ArtistA
        \ArtistB
                \SubLevel2
                         \SubLevel3
        \ArtistC
X:\GenreB
        \ArtistA
        \ArtistB
Right. Limit to n sub levels is missing from location tab. But make sense to me.

And maybe something like:
?Air /1 to search in all subfolders
?Air /2 to search in all subfolders of all subfolders
?Air /3 to... (you get it)

Re: How to search in all direct subfolders ie. NOT recursive

Posted: 26 Oct 2011 18:11
by Reve_Etrange
Jerry wrote:I think he actually needs to recurse but not more than 1 level down in each subfolder. So he's at the root of his music drive with say, 10 different Genre subfolders, each containing multiple Artist subfolders. He wants to match no further down than the Artist subfolders directly under each Genre subfolder. (I have this same hierarchy myself, replicated on multiple attached drives.)
Exactly.

I have a lot of crashes while playing with quick search in the address bar, by the way.

Re: How to search in all direct subfolders ie. NOT recursive

Posted: 26 Oct 2011 18:48
by TheQwerty
It can be indirectly achieved today by:
  • Select the subfolders to search within.
  • In Find Files under location:
    1. Disable "Include subfolders"
    2. Enable "Selected Locations"
  • Perform your search.
Unfortunately, this doesn't help in the case of quick searches, but you could script this and make it an alias. (I was going to try to do that this morning but haven't had the time.)

A similar feature to define the depth of the search had been previously discussed here: http://www.xyplorer.com/xyfc/viewtopic.php?f=3&t=4876
It was generally well received but Don went silent after expressing concerns with how to implement the corresponding GUI. :?

Re: How to search in all direct subfolders ie. NOT recursive

Posted: 26 Oct 2011 19:14
by Reve_Etrange
I guess putting a cap on recursion is not worth the trouble, since using anything than 1 (if set) must be very rare.
I read in the doc that there is some "path" option that looks useful:
The XYplorer documentation wrote:Path If checked, the search term is compared with the whole path/name instead of the name only.
Note that in the search patterns you have to escape any backslashes "\" with backslashes "\" (i.e. double them: "\\"). For example, if "Path" is ON then:
The term "!\\temp\\" will exclude all items inside/below a "temp" folder from the results.
The term ":\\keyboard or \\mouse" will find all items inside/below a "keyboard*" or "mouse*" folder.
The term ":*\\Inbox\\*.msg and not *\\Inbox\\*\\*.msg" will find all *.msg files the are located directly inside all folders named "Inbox".
Alternatively to adding backslashes, you can quote the pattern to protect it from parsing:

:!"*\temp\*"
:"*\keyboard*" OR "*\mouse*"
So, I just would like to be able to use it in the address bar for quick searches, probaby with some flag (eg. /p).

Re: How to search in all direct subfolders ie. NOT recursive

Posted: 26 Oct 2011 19:47
by TheQwerty
The scripting solution...
Save this to a file in your script directory, for now let's call it "SearchSubfolders.xys":

Code: Select all

"Search Folders"
	// Try selected paths
	$location = Report('{Dir {FullName};||{FullName};}', 1);

	// If no selection: try listed paths.
	if (! IsSet($location) OR $location Like '') {
		$location = Report('{Dir {FullName};||{FullName};}');
	}

	// If none listed: use current path.
	if (! IsSet($location) OR $location Like '') {
		$location = "<curpath>";
	}


	// If no query provided: prompt user.
	Global($query);
	if (! IsSet($query) OR $query Like '') {
		$query = Input('Search Query', "Enter your search terms:<crlf><crlf>Note that if query does not contain '/' then it will be appended to prevent searching subfolders.", "$query");
	}

	// We add '/' to the query if it isn't there to prevent recursive searching.
	$query = RegexReplace("$query", '^([^/]*)$', '$1 /');

	Goto "$location?$query";
You could just run the script but let's add an alias so it's not too far off of the quick searches. So run this in your address bar:

Code: Select all

@subSearch=Global($query);$query="<@0>";Load('SearchSubfolders.xys');
Now you can execute it using:

Code: Select all

@subSearch [query]
Let me explain the logic in the location determination:
If the current selection contains folders or drives then they are used.
Else if there are any folders or drives currently displayed in the list they are used.
Finally, if neither of those is true it will search the current path. (Not terribly desirable but tough! :P)

Also, I add the '/' to the end of the given query (unless it already contains '/'), to tell XY to disable recursive searching.

Re: How to search in all direct subfolders ie. NOT recursive

Posted: 26 Oct 2011 20:50
by Reve_Etrange
TheQwerty wrote:The scripting solution...
Seems to work, well done.
Will XYplorer remember the @subSearch alias after I close it?

Re: How to search in all direct subfolders ie. NOT recursive

Posted: 26 Oct 2011 21:04
by TheQwerty
Reve_Etrange wrote:
TheQwerty wrote:The scripting solution...
Seems to work, well done.
Will XYplorer remember the @subSearch alias after I close it?
It sure will.

EDIT: And of course you can rename @subSearch and SearchFolders.xys to whatever you like, you just need to change the loaded file name in the alias as well.

Re: How to search in all direct subfolders ie. NOT recursive

Posted: 07 Nov 2011 14:17
by Reve_Etrange
Thank you again TheQwerty, I use your script almost every day lol.

Re: How to search in all direct subfolders ie. NOT recursive

Posted: 08 Nov 2011 07:27
by kotlmg
can you please add search subfolders recursively to the above code. i.e the code should have two options i.e. 1. search non recursively and 2. search recursively.