(view source code of diskuse.bat as plain text)
@ECHO OFF
:: Use local variablesIF "%OS%"=="Windows_NT" SETLOCAL
:: Check command line arguments and Windows versionIF "%~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 headerECHO Directory Space used (MB)
ECHO.========= ===============
:: Display disk usage for start directoryIF 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:SubDirsFOR /D %%A IN (*.*) DO CALL :List "%%~A"
:: DonePOPD
GOTO End
:List:: Set variable value to bytes used by directoryFOR /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 1MBSET /A ListDir=%ListDir%+524288
:: Integer divide by 1MBSET /A ListDir=%ListDir%/1048576
:: Display resulting value in MBECHO.%~1 %ListDir%
:: Clear variableSET ListDir=
GOTO:EOF
:SyntaxECHO.
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
:EndIF "%OS%"=="Windows_NT" ENDLOCAL
page last modified: 2025-10-11; loaded in 0.0079 seconds