I need a Batch file ( .BAT ) that reads all folders in a directory (not counting the subfolders) and returns them in a variable.
I need a Batch file ( .BAT ) that reads all folders in a directory (not counting the subfolders) and returns them in a variable.
Why the -1 ?. Anyway I solve it for those who are curious use only this line:
@Echo off Dir / ad | find "dirs" > dir.txt
For / f "" %% A IN (dir.txt) do if not defined _folders set "_folders = %% A"
Echo Total folders ^ >% _ folders%
Thanks anyway;)
for /f %%a in ('dir /ad /b ^| find /c /v ""') do echo Total carpetas: %%a
dir /ad /b
command generates the list of folders (not including .
and ..
) This list is filtered by the find
command
find
command counts ( /c
) the number of lines that do not comply ( /v
) the condition of not containing any characters ( ""
) for /f
that stores in %%a
(the replaceable parameter indicated) the number of folders.