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.
Get the total size of all subdirectories with a specific name
Moderator: DosItHelp
-
- Posts: 16
- Joined: 22 Jul 2018 04:59
Re: Get the total size of all subdirectories with a specific name
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
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
-
- Posts: 16
- Joined: 22 Jul 2018 04:59
Re: Get the total size of all subdirectories with a specific name
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:
how this can be done in:
I really appreciate any advice.
Many thanks ..
T.
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
Code: Select all
set "folder=%userprofile%\Desktop"
Many thanks ..
T.
Re: Get the total size of all subdirectories with a specific name
Basically not a big deal
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
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
Steffen
-
- Posts: 16
- Joined: 22 Jul 2018 04:59
Re: Get the total size of all subdirectories with a specific name
I'm more than obliged to you Steffen, thank you very very much.
My best regards,
T.
My best regards,
T.