I just want to know how can I get all the names of the folders in a current directory. For example in my current directory I have three folders:
stackoverflow reddit codinghorror
Then when I execute my batch script all the three folders will print in the screen.
How can I achieve this?
Using batch files:
for /d %%d in (*.*) do echo %%d
If you want to test that on the command line, use only one % sign in both cases.
On Windows, you can use:
dir /ad /b
/ad
will get you the directories only/b
will present it in 'bare' format
EDIT (reply to comment):
If you want to iterate over these directories and do something with them, use a for
command:
for /F "delims=" %%a in ('dir /ad /b') do (
echo %%a
)
%
- this is for use in a batch, if you use for on the command line, use a single %
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With