How do I search for files and exclude subfolders in Windows 7?

31

4

The Windows 7 search dropdown always searches within sub folders, but I only want to search the current folder. How can I do this?

user1611961

Posted 2013-05-23T15:19:04.417

Reputation:

Answers

22

A way to do this (in Windows 7) is to discard all subfolders using -folder: with \*, for example (when searching for .zip files inside the downloads folder):

*.zip -folder:"Downloads\*"


That's all.

Ivan Castellanos

Posted 2013-05-23T15:19:04.417

Reputation: 404

3Or to generalize to any current directory: *.zip -folder:".\*" – protongun – 2014-12-29T23:41:05.433

1NVM, the above doesn't work as expected. Perhaps someone can offer a correction? – protongun – 2014-12-29T23:47:50.697

.zip -folder:".\" also excludes the current directly (as well as sub-directories). The above example works correctly to only exclude all sub-directories if "Downloads" is the current working directly. – ashtonium – 2015-02-04T16:59:25.313

I'm trying to understand the syntax. So Spaces are treated like AND booleans, there are basically two conditions. (1)That the file names all end in .zip and (2) -folder:"Downloads\*" To me the second condition looks like it is excluding both Downloads and it's subfolders ... Why does it only exclude the subfolders? I understand it would not be useful to exclude all folders and that it successfully answers OP -- I'm just saying that is how it looks to me, so I don't understand it. – Xzila – 2016-08-16T17:06:43.897

1@Xzila Its thanks to the trailing slash, let me give you a simple example, if we have the file "foo.zip", what is its folder? its folder is "C:\Downloads", it is NOT "C:\Downloads", so when you do "-folder:"Downloads\*" it matches the later but not the former, effectively excluding only subdirectories – Ivan Castellanos – 2016-08-27T14:27:52.750

1unix/Linux users, think carefully, "-folder:" is exclude the matching folder, negating the "folder:" clause. Semantic overload leaking in from the find command strikes again. – BenPen – 2016-11-08T20:02:26.260

6

In order to not search in sub-folders, in the search window, click "organize" (upper left corner) and select the option "Folder and search options." In that window, select the "Search" tab. Unselect the the option "Include subfolders in search results..." That will do the trick!

user226364

Posted 2013-05-23T15:19:04.417

Reputation:

1That will NOT do the trick. And that is a rotten glaring DANGEROUS bug in Explorer. Think Search -> Ctrl-A -> Delete. Subfolders are ALWAYS searched from the Explorer search box. – None – 2014-07-26T23:08:40.260

1Nick is most definitely wrong. In Windows 7 this works. – R-D – 2014-08-01T11:26:32.443

6This is a permanent change for a casual/ephemeral search, it doesn't make any sense to do this. – Ivan Castellanos – 2014-12-16T09:02:30.203

5

-folder:(name_of_subfolder) will exclude "name_of_subfolder" from the search results.

On the Microsoft website, see Advanced Query Syntax for more options (some of which may be outdated), and Advanced tips for searching in Windows which uses a newer syntax such as System.Kind:<>picture, but seems to be less complete.

user43210

Posted 2013-05-23T15:19:04.417

Reputation: 59

This sort of parameter is exactly what I was looking for! – NiteCyper – 2014-11-17T13:11:06.057

1@NiteCyper, did it work for you in Windows 7? (I am not on Windows, but it seems the parameter is outdated? See the links I added to the answer.) – Arjan – 2014-12-14T09:43:48.300

For future readers: it seems that System.FileName can also match directory names, so then maybe System.FileName<>name_of_subfolder would work. Also, System.Kind might allow for System.Kind:<>folder to exclude all folders (or when combined with System.FileName specific folders?). And it seems one might use this long list in search. (But: I am not using Windows.)

– Arjan – 2014-12-14T09:51:17.493

@Arjan Yes, I use Windows 7. Windows 7 seems to have automatically removed the colon. – NiteCyper – 2014-12-16T00:18:04.333

4

to ignore folders (not their contained files), then try:

System.Kind:<>folder

T.Todua

Posted 2013-05-23T15:19:04.417

Reputation: 2 436

3This works on Windows 10 – Matthew – 2018-10-08T03:16:59.007

2

*.zip folder:"\MyFolder"

This must be run from the parent folder to search MyFolder, but none of MyFolder's sub-folders or sibling folders. The double quotes and the leading backslash appear to be required. I tested this on Windows 7 and it worked. I found this answer here: answers.microsoft.com: how do I NOT search subdirectories

While I found the excluding folder option from another answer worked (thanks), if you have a lot of subfolders to exclude, this option is likely easier.

FreeText

Posted 2013-05-23T15:19:04.417

Reputation: 71

On Windows 8, I was also able to run this from within the directory to be searched. E.g., in C:\foo, enter *.zip folder:"\foo" in the search box. Thanks for the info and link! – cxw – 2017-09-01T13:50:47.053

1

In Windows 10, you can select Current Folder in the Ribbon toolbar

enter image description here

Abdulrahman Bres

Posted 2013-05-23T15:19:04.417

Reputation: 125

0

I'm on a Windows 10 machine, but I doubt whether things have changed. If I'm right the above answers are wrong.

In the search box

If you go:
common*source
... this brings up all files and folders with the substring "common" followed by the substring "source": e.g. commons-collections4-4.0-sources.jar

NB For some unaccountable (Micro$oft) reason, even if you have set the thing NOT to search for file contents in "Advanced options", it will still search the contents of files if you don't precede the search string by "name:" or "filename:"

If you go:
name: common*source
... nothing comes up!

If you go:
filename: common*source
... this brings up all files and folders with the substring "common" followed by the substring "source": e.g. commons-collections4-4.0-sources.jar

If you go:
filename: common
... it will bring up all files and folders which have "common" in their name.

If you go:
filename: common -folder
... it will bring up only files (no folders) with "common" in their name

Note the difference between "name" and "filename". I suspect that in the first case it is using a "property" of the file hidden somewhere, and that most of the time you will want to be searching for "filename".

Also note that use of the wildcard * requires that the part before it precedes the part after it (of course). If you want these substrings to appear in your filename in any order it's a bit tricky. You have to do something like this:

filename: "*test*" AND "*co*" -folder

... which is equivalent to this:

filename: "*co*" AND "*test*" -folder

or indeed this:

filename: "*test*" + "*co*" -folder

mike rodent

Posted 2013-05-23T15:19:04.417

Reputation: 367