Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

count folders and subfolders with batch file

Tags:

batch-file

cmd

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!

like image 897
Mark Avatar asked Oct 31 '13 14:10

Mark


People also ask

How do I count files in a folder and subfolders?

To count all the files and directories in the current directory and subdirectories, type dir *. * /s at the prompt.

How do you count subfolders?

If you want to count the subfolders in a folder, run this command: dir /a:d /s /b "Folder Path" | find /c ":".

How do I count the number of folders in Windows?

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.


1 Answers

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!
like image 71
DanielBarbarian Avatar answered Sep 22 '22 08:09

DanielBarbarian