display the count of files in folders

Microsoft Windows
Post Reply
SweetTasha
Posts: 5
Joined: 2021-Sep-11, 4:24 am

display the count of files in folders

Post by SweetTasha »

Is there a CMD that will show the number of files in a given folder. Perhaps even traverse the tree. Like suppose I have a folder called Documents with subfolders A and B, subfolder A has 3 subfolders and B has 2 So the "tree" looks like this:

C;/Documents
A
A1
A2
A3
B
B1
B2
The command I'm thinking of would create a report something like this

FOLDER SUBS TOTAL SIZE

C:\Documents 2 nn,nnn
A 3 n,nnn
A1 -- nnn
etc. etc.etc

I seem to remember a TREE command! :roll:

Thanks for your help. SweetTasha.
SimonLothar
Posts: 1
Joined: 2021-Sep-26, 6:43 pm

Re: display the count of files in folders

Post by SimonLothar »

Possibly this piece of code would do for a start:

Code: Select all

@echo off
SET ID=
if "%LANGUAGE%" EQU "de" SET ID=Datei(en)
if "%LANGUAGE%" EQU "en" SET ID=File(s)
if "%ID%" EQU "" goto :eof

SET STARTDIR=c:\powershell
call :func1 "%STARTDIR%"
for /f "delims=" %%A  in ('dir "%STARTDIR%" /S /AD /B') do call :func1 "%%A"
goto :eof

:func1
for /f "delims=," %%A  in ('dir "%~1" ^| find "%ID%"') do call :func2 "%~1" "%%A"
goto :eof

:func2
SET COUNT=%~2
if "%LANGUAGE%" EQU "de" SET COUNT=%COUNT:Datei(en)=%
if "%LANGUAGE%" EQU "en" SET COUNT=%COUNT:File(s)=%
SET COUNT=%COUNT: =%
ECHO %~1, %COUNT%
goto :eof
Output would look like this
c:\powershell, 30
c:\powershell\INST_SVN, 1
c:\powershell\kh, 3
c:\powershell\modules, 1
c:\powershell\nppBackup, 12
c:\powershell\WindowsPowerShell, 4
c:\powershell\INST_SVN\BLCSP, 1
...
Perhaps some adjustments concerning the language have to be applied.
Post Reply