BATCH: Count the folders inside a directory and return them in a variable

0

I need a Batch file ( .BAT ) that reads all folders in a directory (not counting the subfolders) and returns them in a variable.

    
asked by RazorRipzee 05.05.2017 в 19:30
source

2 answers

0

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;)

    
answered by 05.05.2017 / 20:15
source
0

for /f %%a in ('dir /ad /b ^| find /c /v ""') do echo Total carpetas: %%a
  • The dir /ad /b command generates the list of folders (not including . and .. ) This list is filtered by the find command
  • The find command counts ( /c ) the number of lines that do not comply ( /v ) the condition of not containing any characters ( "" )
  • The result is processed by a for /f that stores in %%a (the replaceable parameter indicated) the number of folders.
answered by 08.05.2017 в 15:49