Windows batch file - display all sub-folders

不问归期 提交于 2020-01-01 19:13:09

问题


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

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?

Thanks.


回答1:


You can use the dir command with the modifier /a:d which will tell it to only search directories

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

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




回答2:


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

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


来源:https://stackoverflow.com/questions/7664929/windows-batch-file-display-all-sub-folders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!