b***@lycos.com
2014-01-18 16:33:35 UTC
Greetings,
http://www.bish.co.uk/forum/index.php?topic=58.0 provides some scripts to find the size of each filesystem subtree rooted at a directory. These scripts have the limitation that the loop never quits and to exit the batch file you need to use Ctrl-C and then type ECHO ON to get your DOS prompt back. I have modified the script to get past this limitation. Here's my code. Enjoy.
Thanks,
Bhat
::--------------------------------------------------------
:: Recursion
:: Invokes the 'dirsize' subroutine
::--------------------------------------------------------
echo off
set WORKING_DIRECTORY=%cd%
for /f "delims=" %%a in ('dir /a:D /D /B /S') do (
echo off
cd %%a
%%"%WORKING_DIRECTORY%"\dirsize "%%a" 2>NUL
call:dirsize "%%a"
cd %WORKING_DIRECTORY%
)
::--------------------------------------------------------
:: 'dirsize' Subroutine starts here
::--------------------------------------------------------
:dirsize
@echo off
setLocal EnableDelayedExpansion
set /a value=0
set /a sum=0
FOR /R %1 %%I IN (*) DO (
set /a value=%%~zI
set /a sum=!sum!+!value!
)
@echo %CD% !sum!
http://www.bish.co.uk/forum/index.php?topic=58.0 provides some scripts to find the size of each filesystem subtree rooted at a directory. These scripts have the limitation that the loop never quits and to exit the batch file you need to use Ctrl-C and then type ECHO ON to get your DOS prompt back. I have modified the script to get past this limitation. Here's my code. Enjoy.
Thanks,
Bhat
::--------------------------------------------------------
:: Recursion
:: Invokes the 'dirsize' subroutine
::--------------------------------------------------------
echo off
set WORKING_DIRECTORY=%cd%
for /f "delims=" %%a in ('dir /a:D /D /B /S') do (
echo off
cd %%a
%%"%WORKING_DIRECTORY%"\dirsize "%%a" 2>NUL
call:dirsize "%%a"
cd %WORKING_DIRECTORY%
)
::--------------------------------------------------------
:: 'dirsize' Subroutine starts here
::--------------------------------------------------------
:dirsize
@echo off
setLocal EnableDelayedExpansion
set /a value=0
set /a sum=0
FOR /R %1 %%I IN (*) DO (
set /a value=%%~zI
set /a sum=!sum!+!value!
)
@echo %CD% !sum!