JSI Tip 9571. How can I generate a report of sorted file sizes?

Using DiskUse.exe, VLen.bat, and Numeric.bat, I have scripted Size.bat to generate a file containing FileSize,"Owner","FileName", sorted by largest to smallest.

The syntax for using Size.bat is:

Size DriveLetter IgnoreSize Report


DriveLetter is the disk drive letter that you wish to enumerate.

IgnoreSize  is the smallest size that you wish to report. If you wish to report all size, use a 0.

Report      is the path to the output file.
Size.bat contains:
@echo off
if \{%3\}==\{\} goto :Err
set wrk1=%1
set drv=%wrk1:~0,1%:
set ignore=%2
call numeric %ignore% OK
if "%OK%" EQU "N" goto Err 
if "%ignore%" NEQ "0" if "%ignore:~0,1%" EQU "0" goto Err
set /a ignore=%ignore%
set output=%3
if exist %output% del /q %output%
set wrk1="%TEMP%\SIZE_%RANDOM%.TMP"
set wrk2="%TEMP%\SIZE_%RANDOM%.TMP"
set wrk3="%TEMP%\SIZE_%RANDOM%.TMP"
diskuse %drv% /s /v /t /x:%ignore% /f:%wrk1%
set owner="UNKNOWN"
for /f "Skip=2 Tokens=1,2* Delims=," %%a in ('type %wrk1%') do (
 set p1=%%a
 set p2=%%b
 set p3=%%c
 call :parse
sort /R %wrk2% /O %wrk3%
for /f "Tokens=2-4 Delims=," %%a in ('type %wrk3%') do (
 @echo %%a,%%b,%%c>>%output%
if exist %wrk1% del /q %wrk1%
if exist %wrk2% del /q %wrk2%
if exist %wrk3% del /q %wrk3%
goto :EOF
set own=%p3::=%
if "%own%" EQU "%p3%" goto own
call VLen %p1% numbers
set sz=000000000000000
set /a zeros=12 - %numbers%
call set sz=%%sz:~0,%zeros%%%%p1%
@echo %sz%,%p1%,%owner%,"%p3%">>%wrk2%
goto :EOF
set owner="%p1%\%p2%"
goto :EOF
@echo Syntax: SIZE DriveLetter IgnoreSize Report

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.