Page 1 of 1

Get the total size of all subdirectories with a specific name

Posted: 28 Sep 2020 04:03
by terryhenderson
I have a long and deep tree which contains numerous subdirectories for many levels down.
"resfiles" is one of those subdirectories that exists in various levels of that tree.
What I need is a cmd or a batch that sums the total size of all resfiles subdirectories in all levels and returns:
1. the number of resfiles subdirectories
2. the total size of all those resfiles subdirectories of that tree.


Can I get some precious assistance with this issue, please?

Many thanks in advance.

T.

Re: Get the total size of all subdirectories with a specific name

Posted: 28 Sep 2020 10:59
by aGerman
There are some threads about the size of a directory here at DosTips, like that one:
viewtopic.php?f=3&t=9615&p=62024

Although I still have my doubts that Batch is the right language for a task like this. Even if you are able to get the total size, keep in mind that math in Batch is limited to 32 bit integers.

Steffen

Re: Get the total size of all subdirectories with a specific name

Posted: 29 Sep 2020 04:38
by terryhenderson
Thank you very much indeed Steffen for your reply.
I believe the referred to link does have the solution for my question. I just need to specifically refer to any "resfiles" subfolder in this code:

Code: Select all

@echo off &setlocal
set "folder=%userprofile%\Desktop"
for /f "tokens=1,2 delims=: " %%a in ('robocopy "%folder%" "%folder%" /L /S /NJH /BYTES /FP /NC /NDL /NFL /TS /XJ /R:0 /W:0') do if /i "%%a"=="Bytes" set "size=%%b"
echo %size% bytes
pause
how this can be done in:

Code: Select all

set "folder=%userprofile%\Desktop"
I really appreciate any advice.

Many thanks ..

T.

Re: Get the total size of all subdirectories with a specific name

Posted: 29 Sep 2020 10:44
by aGerman
Basically not a big deal

Code: Select all

@echo off &setlocal
set "root=C:\somewhwere"
set "folder=resfiles"

set /a "count=0,size=0"
for /f "delims=" %%i in ('dir /ad /b /s "%root%\*%folder%"^|findstr /eic:"\\%folder%"') do (
  set /a "count+=1"
  for /f "tokens=1,2 delims=: " %%a in ('robocopy "%%i" "%%i" /L /S /NJH /BYTES /FP /NC /NDL /NFL /TS /XJ /R:0 /W:0') do if /i "%%a"=="Bytes" set /a "size+=%%b"
)

echo %count%
echo %size%
pause
But now you have the SET /A statement to summerize the the sizes of the found directories. I can't see on your desktop and thus, I have no idea if the 32 bit limit I've been talking about might be problematic in your case. However, anything above 2147483647 isn't recognized as a numeric value anymore. In case of the size this means 2GB is already one byte too much.

Steffen

Re: Get the total size of all subdirectories with a specific name

Posted: 29 Sep 2020 13:55
by terryhenderson
I'm more than obliged to you Steffen, thank you very very much.
My best regards,

T.