43

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

Worthwelle
  • 4,538
  • 11
  • 21
  • 32
  • Related:  [How to search for only folders in Windows 7 instead of folders AND files](https://superuser.com/q/116514/150988)  and  [How can I see the available Windows Search Filters?](https://superuser.com/q/531659/150988) – Scott - Слава Україні Feb 11 '18 at 17:29

7 Answers7

28

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
  • 480
  • 1
  • 5
  • 12
  • 3
    Or to generalize to any current directory: ``*.zip -folder:".\*"`` – protongun Dec 29 '14 at 23:41
  • 2
    NVM, the above doesn't work as expected. Perhaps someone can offer a correction? – protongun Dec 29 '14 at 23:47
  • *.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 Feb 04 '15 at 16:59
  • 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 Aug 16 '16 at 17:06
  • 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 Aug 27 '16 at 14:27
  • 1
    unix/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 Nov 08 '16 at 20:02
  • `-cartella` instead of `-folder` for Italian localization – massic80 May 04 '21 at 10:39
9

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

System.Kind:<>folder
T.Todua
  • 3,815
  • 9
  • 42
  • 57
7

-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.

Arjan
  • 30,974
  • 14
  • 75
  • 112
user43210
  • 79
  • 1
  • 2
  • This sort of parameter is exactly what I was looking for! – NiteCyper Nov 17 '14 at 13:11
  • 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 Dec 14 '14 at 09:43
  • For future readers: it seems that `System.FileName` [can also match directory names](http://msdn.microsoft.com/en-us/library/windows/desktop/bb760703), so then maybe `System.FileName<>name_of_subfolder` would work. Also, [System.Kind](http://msdn.microsoft.com/en-us/library/windows/desktop/bb787521) 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](http://msdn.microsoft.com/en-us/library/windows/desktop/ff521735) in search. (But: I am not using Windows.) – Arjan Dec 14 '14 at 09:51
  • @Arjan Yes, I use Windows 7. Windows 7 seems to have automatically removed the colon. – NiteCyper Dec 16 '14 at 00:18
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!

  • 1
    That 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. –  Jul 26 '14 at 23:08
  • 1
    Nick is most definitely wrong. In Windows 7 this works. – R-D Aug 01 '14 at 11:26
  • 6
    This is a permanent change for a casual/ephemeral search, it doesn't make any sense to do this. – Ivan Castellanos Dec 16 '14 at 09:02
3

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

enter image description here

3

*.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
  • 181
  • 4
  • 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 Sep 01 '17 at 13:50
1

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
  • 653
  • 1
  • 9
  • 24