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*
精彩评论