TyC
TyC

Reputation: 792

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.

Upvotes: 3

Views: 12025

Answers (2)

refaim
refaim

Reputation: 1885

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

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

Upvotes: 3

Andrew
Andrew

Reputation: 1357

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*

Upvotes: 6

Related Questions