Windows 批处理文件 - 显示所有子文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7664929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:12:18  来源:igfitidea点击:

Windows batch file - display all sub-folders

windowsbatch-filesubdirectory

提问by TyC

I'm having difficulty returning JUST folders (ignore files) using a windows batch file.

我无法使用 Windows 批处理文件返回 JUST 文件夹(忽略文件)。

Here's what I have right now. Currently it's returing files and sub-sub-folders.

这就是我现在所拥有的。目前它正在恢复文件和子文件夹。

for /r %%g in ("xx*") do echo %%g

Also, say I want to only return the folders that start with a couple different prefixes.

另外,假设我只想返回以几个不同前缀开头的文件夹。

For example: I want to echo only the folders that start with w*, we*, cm*, cr*, etc under within in the folder "work". I do Is this possible using a batch file?

例如:我只想回显文件夹“work”中以 w*、we*、cm*、cr* 等开头的文件夹。我可以使用批处理文件吗?

Thanks.

谢谢。

回答by Andrew

You can use the dircommand with the modifier /a:dwhich will tell it to only search directories

您可以使用dir带有修饰符的命令,/a:d它会告诉它只搜索目录

FOR /f "tokens=*" %%i in ('DIR /a:d /b w*') DO (
    ECHO %%i
)

This will find all of the subfolders that start with w*

这将找到所有以 w*

回答by refaim

Here's modified version of Andrew's answer that can handle multiple prefixes:

这是安德鲁答案的修改版本,可以处理多个前缀:

dir /a:d /b w* we* cm* cr*