Windows equivalent of ls * (asterisk) directory wildcarding

command linesearchwindows

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.

Best Answer

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.

Related Question