I am looking to create a batch file that when given a pathway, it will count all the folders and sub folders within it. So far I am only able to gather the number of folders within the 1st level of the pathway. I will then pipe it to a text file.
Here's what I have so far:
for /f %%a in ('dir /b /ad %folder%^|find /c /v "" ') do set count=%%a
echo %count% folder(s^)>> !output!
Am I close to getting what I want? What do I need to tweek?
Thanks!
To count all the files and directories in the current directory and subdirectories, type dir *. * /s at the prompt.
If you want to count the subfolders in a folder, run this command: dir /a:d /s /b "Folder Path" | find /c ":".
Use File Explorer Open the folder and select all the subfolders or files either manually or by pressing CTRL+A shortcut. If you choose manually, you can select and omit particular files. You can now see the total count near the left bottom of the window.
Add /s
to include all subfolders:
for /f %%a in ('dir /b /s /ad %folder%^|find /c /v "" ') do set count=%%a
echo %count% folder(s^)>> !output!
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