Windows equivalent of ls * (asterisk) directory wildcarding?

Another question from an long-time Unix/Linux user who finds himself in a Windows world. First let me explain exactly what I'm trying to do. I'm using the Windows cmd.exe shell, and I want to list all directories below the current directory that contain a bin\Debug hierarchy, and determine if they contain any files (e.g.: trying to figure out if my NAnt clean target is working properly). My hierarchy might look something like this:

\Current
    \DirA
         \bin
             \Debug
                  (some files under debug)
             \Release
    \DirB
         \bin
             \Debug
    \DirC
         \bin
             \Release

In Unix, ls */bin/Debug would just give me a list of all the stuff in DirA/bin/Debug, and show me the fact that DirB/bin/Debug is empty. I've tried different contortions in the cmd shell, but keep winding up with stuff like:

    > dir *\bin\Debug
    The filename, directory name, or volume label syntax is incorrect.

    > dir *\*\*
    The filename, directory name, or volume label syntax is incorrect.

Is there something subtle I don't understand about the dir command, or is it just limited that way?

Yes, I realize I can just switch to explorer, navigate, right-click, and probably eventually craft a search that does what I want, but I'm more interested in the quick-n-dirty command-line solution.


Something like this should do what you want. At the root directory of the project type:


c:\path\to\slndir>dir *.dll *.exe /s /b | findstr /i "bin\debug"

Dir arguments: /s - recursive, /b - "bare", no extra info
findstr arguments: /i - ignore case

In general, 'help command' will show help for the shell commands. If that doesn't work, then
'command /?' will generally show help.


Windows doesn't do wildcards the way Linux does. Only the filename portion can contain wildcards.

You can download a version of ls that runs on Windows and use that. I've used Cygwin, but I'm sure there are others.


@for /D /r %P in (.) do @for %Q in ("%~fP\bin\Debug\*") do @echo %~ftzaQ

Not nice, but should work. You may also put into a .cmd file (then replace every single % into double %%). Or define a macro using doskey (yes, it still exists).

Ensure that cmd extensions are enabled.

EDIT: How it works:

The first for loop iterates through all subdirectories (/D and /r switch) iteratively. %~fP expands to the full path of that directory. Then, it appends \bin\Debug* to that path. The second for loop enumerates all files that match. %~ftzaQ is expanded to every file match and printed to the screen by echo. The strange %~ftzaQ formats it like a dir output. The @ character avoids that the commands itself are printed on the screen.

For more, see

  • http://technet.microsoft.com/en-us/library/bb490909.aspx
  • http://www.ss64.com/nt/for.html
  • http://www.ss64.com/nt/for_r.html

unxutils has an ls command. The problem is really with the windows shell, however. On unix your shell will expand */bin/Debug into the relevant pathnames and feed them to the ls command as separate command-line arguments.

Cygwin would certainly do the trick for you, or you could try a windows port of a unix shell such as bash. If you wanted to go the scripting route, you could code up something in python pretty easily using the glob module, and most other scripting languages have an equivalent.