Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows batch file - display all 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 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.

like image 396
TyC Avatar asked May 20 '26 22:05

TyC


1 Answers

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*

like image 72
Andrew Avatar answered May 22 '26 13:05

Andrew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!