(view source code of diskuse.bat as plain text)
@ECHO OFF
:: Use local variables
IF "%OS%"=="Windows_NT" SETLOCAL
:: Check command line arguments and Windows version
IF "%~1"=="/?" GOTO Syntax
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
:: Go to start directory
:: The original version did not use doublequotes for %CD%, making the code vulnerable to code
:: insertion exploits, as explained at http://www.thesecurityfactory.be/command-injection-windows.html
:: As we will use %StartDir% only for the following PUSHD operation, doublequotes do not inhibit
:: the code from working properly - problem solved.
SET StartDir="%CD%"
IF NOT "%~1"=="" SET StartDir="%~1"
PUSHD %StartDir%
:: Display header
ECHO Directory Space used (MB)
ECHO.========= ===============
:: Display disk usage for start directory
IF NOT EXIST *.* GOTO SubDirs
FOR /F "tokens=3,4*" %%A IN ('DIR "%~1" /A-D /-C ^| FIND /I "File(s)"') DO SET .\=%%A
SET /A .\=.\+524288
SET /A .\=.\/1048576
ECHO..\ %.\%
SET .\=
:: Display disk usage for every subdirectory
:SubDirs
FOR /D %%A IN (*.*) DO CALL :List "%%~A"
:: Done
POPD
GOTO End
:List
:: Set variable value to bytes used by directory
FOR /F "tokens=3,4*" %%B IN ('DIR /A /-C /S "%~1" ^| FIND /I "File(s)"') DO SET ListDir=%%~B
:: Add 0.5MB in order to properly round the value when integer divided by 1MB
SET /A ListDir=%ListDir%+524288
:: Integer divide by 1MB
SET /A ListDir=%ListDir%/1048576
:: Display resulting value in MB
ECHO.%~1 %ListDir%
:: Clear variable
SET ListDir=
GOTO:EOF
:Syntax
ECHO.
ECHO DiskUse, Version 4.20 for Windows NT 4 / 2000 / XP
ECHO Display disk space used by subdirectories (tab delimited)
ECHO.
ECHO Usage: DISKUSE [ startdir ]
ECHO.
ECHO Where: "startdir" is the directory containing subdirectories to be
ECHO inventoried (default is the current directory)
ECHO.
ECHO Note: Due to batch math limitations this batch file will return negative
ECHO numbers if the disk space used by subdirectories exceeds 2GB.
ECHO For Windows 2000/XP, upgrade to version 5 and use its /L switch.
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
:End
IF "%OS%"=="Windows_NT" ENDLOCAL
page last modified: 2024-04-16; loaded in 0.0085 seconds