开发者

Windows batch file - display all sub-folders

开发者 https://www.devze.com 2023-04-10 17:21 出处:网络
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.

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 t开发者_JAVA技巧he 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.


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*


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

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号