How can I search for files in the Windows command line, using wildcards like this?

  • 2
    For what are you trying to use the wildcard search? A command line program, .bat file? For a .bat file scenario, just use nested batch for loops. for /d %%D in (C:\Users\*) do for %%F in (%%~fD\AppData\Local\*.txt) do echo %%~fF As for command line programs, the wildchar handling is up to the authors of that specific program. Dec 26, 2012 at 17:11
  • I am trying to search in some path with wildcards in the path, not only in the file name, I need some way using existing windows tools (cmd.exe), or powershell, or some external free tool!
    – Sawan
    Dec 26, 2012 at 17:18

3 Answers 3


Windows PowerShell can do this easily.

Get-ChildItem C:\Users\*\AppData\Local\*.txt

If you want to include subfolders:

Get-ChildItem C:\Users\*\AppData\Local\*.txt -recurse

Regarding Hidden (etc.) files, Powershell's help Get-ChildItem says:

By default, Get-ChildItem gets non-hidden items, but you can use the Directory, File, Hidden, ReadOnly, and System parameters to get only items with these attributes. To create a complex attribute search, use the Attributes parameter. If you use these parameters, Get-ChildItem gets only the items that meet all search conditions, as though the parameters were connected by an AND operator.

  • How to include hidden and system dirs and files?
    – Sawan
    Dec 26, 2012 at 17:39
  • @MohamedSakherSawan check out the edit I added. Dec 26, 2012 at 18:01

Any good Unix shell for Windows will do this.

For example, here's a screenshot of my Hamilton C shell doing your example (sorry, no matches) and a couple others that do produce matches. The ... wildcard used in the third example matches zero or more directory levels, whatever it takes for the rest of the pattern to match.

Wildcarding using Hamilton C shell on Windows 7 x64

And here's how you might do it with Cygwin bash. A few differences here because Cygwin follows Unix conventions: Paths are usually typed with forward slashes and the backslash is the escape character. Since Unix doesn't understand drive letters, they've introduced a /cydrive/c notation to refer to the C: drive. As on Unix, wildcarding is case-sensitive. And while it supports the usual multiple directory level wildcarding you'd like, it doesn't include the ... I added to my shell. (Instead, you'd probably use find.)

Wildcarding using Cygwin bash on Windows 7 x64


In cmd, navigate to C:\Users, and run

dir /s /b | findstr AppData\Local | findstr txt

Explanation: dir /s lists all files recursively, /b displays full path, and within all these child files, use pipeline operator to search both the string 'AppData\Local' and 'txt'.

  • Instead of navigating to C:\Users\, I guess you could give the path as argument to dir.
    – Morten
    Sep 15, 2020 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.