Windows 7 列出具有指定名称的所有子目录

Windows 7 列出具有指定名称的所有子目录,windows-7,batch-file,command-prompt,cmd,Windows 7,Batch File,Command Prompt,Cmd,我正在尝试获取所有子目录(递归)的路径列表,这些子目录具有指定的名称,例如“bin”。问题是,如果当前目录包含该名称的子目录,则DIR命令将仅在该子目录内执行,而忽略其他子目录 例如: C:\DEVELOPMENT\RESEARCH>ver Microsoft Windows [Version 6.1.7601] C:\DEVELOPMENT\RESEARCH>dir *bin* /ad /s /b C:\DEVELOPMENT\RESEARCH\bin C:\DEVELOPME

我正在尝试获取所有子目录(递归)的路径列表,这些子目录具有指定的名称,例如
“bin”
。问题是,如果当前目录包含该名称的子目录,则DIR命令将仅在该子目录内执行,而忽略其他子目录

例如:

C:\DEVELOPMENT\RESEARCH>ver

Microsoft Windows [Version 6.1.7601]

C:\DEVELOPMENT\RESEARCH>dir *bin* /ad /s /b
C:\DEVELOPMENT\RESEARCH\bin
C:\DEVELOPMENT\RESEARCH\Apache\2bin
C:\DEVELOPMENT\RESEARCH\Apache\bin
C:\DEVELOPMENT\RESEARCH\Apache\bin1
C:\DEVELOPMENT\RESEARCH\C#\ConsoleApps\MiscTests\bin

C:\DEVELOPMENT\RESEARCH>dir bin* /ad /s /b
C:\DEVELOPMENT\RESEARCH\bin
C:\DEVELOPMENT\RESEARCH\Apache\bin
C:\DEVELOPMENT\RESEARCH\Apache\bin1
C:\DEVELOPMENT\RESEARCH\C#\ConsoleApps\MiscTests\bin

C:\DEVELOPMENT\RESEARCH>dir bin /ad /s /b
C:\DEVELOPMENT\RESEARCH\bin\test    

C:\DEVELOPMENT\RESEARCH>rmdir bin /s /q

C:\DEVELOPMENT\RESEARCH>dir bin /ad /s /b
C:\DEVELOPMENT\RESEARCH\Apache\bin
C:\DEVELOPMENT\RESEARCH\C#\ConsoleApps\MiscTests\bin

C:\DEVELOPMENT\RESEARCH>
dir*bin*/ad/s/b
输出名称中包含
bin
的所有子目录。这个输出是正常的。与
dir-bin*/ad/s/b
相同,它输出名称以
bin
开头的所有子目录。但是
dir-bin/ad/s/b
只输出当前目录中名为
bin
的第一个子目录的内容。期望输出为:

C:\DEVELOPMENT\RESEARCH\bin
C:\DEVELOPMENT\RESEARCH\Apache\bin
C:\DEVELOPMENT\RESEARCH\C#\ConsoleApps\MiscTests\bin
我怎样才能做到这一点


注意:如果当前目录不包含
bin
子目录,则按预期输出。(我删除了
bin
子目录以显示此内容)

如果当前目录包含
bin
子目录,则很难使用标准的DOS命令。我认为你有三个基本选择:

# Option 1: FOR and check directory existance (modified from MBu's answer - the
# original answer just appended 'bin' to all directories whether it existed or not)
# (replace the 'echo %A' with your desired action)
for /r /d %A in (bin) do if exist %A\NUL echo %A

# Option 2: PowerShell (second item is if you need to verify it is a directory)
Get-ChildItem -filter bin -recurse
Get-ChildItem -filter bin -recurse |? { $_.Attributes -match 'Directory' }

# Option 3: Use UNIX/Cygwin find.exe (not to be confused in DOS find)
# (you can locate on the net, such as GNU Utilities for Win32)
find.exe . -name bin
find.exe . -name bin -type d
这应该可以:

for /R /D %A in (*bin*) do echo %A

选项1起作用。实际上,我正在编写一个短脚本,删除具有给定名称的子目录。我把你的答案(所以我会接受)和其他命令结合起来,得到了我想要的。非常感谢!选项1-在使用NUL的Vista中不起作用。保留\但删除NUL,它可以在Vista中工作。此外,应该使用引号。如果存在“%A\”@dbenham,请在引号中指出正确的点。我很惊讶NUL没有在Vista上工作。我在Win7和Win2008上进行了测试,它成功了,而这篇文章(DOS测试if drive…)提到了Win3.11,所以我希望它几乎适用于所有方面。嗯,我只是在Vista上尝试了NUL,效果很好。但我发誓我在家里的Vista 64上试过,但失败了。我回家后会再检查一遍。我知道在MS-DOS中,检查文件夹是否存在是一项标准技术。但我记得我知道Windows引入了一些复杂因素,使得它在某些情况下不可靠——我只是记不起细节。