Powered by GeSHi

Source code for diskuse.bat

(view source code of diskuse.bat as plain text)

  1. @ECHO OFF
  2. :: Use local variables
  3. IF "%OS%"=="Windows_NT" SETLOCAL
  4.  
  5. :: Check command line arguments and Windows version
  6. IF "%~1"=="/?" GOTO Syntax
  7. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  8.  
  9. :: Go to start directory
  10. SET StartDir=%CD%
  11. IF NOT "%~1"=="" SET StartDir=%~1
  12. PUSHD "%StartDir%"
  13.  
  14. :: Display header
  15. ECHO Directory	Space used (MB)
  16. ECHO.=========	===============
  17.  
  18. :: Display disk usage for start directory
  19. IF NOT EXIST *.* GOTO SubDirs
  20. FOR /F "tokens=3,4*" %%A IN ('DIR %1 /A-D /-C ^| FIND /I "File(s)"') DO SET .\=%%A
  21. SET /A .\=.\+524288
  22. SET /A .\=.\/1048576
  23. ECHO..\	%.\%
  24. SET .\=
  25.  
  26. :: Display disk usage for every subdirectory
  27. :SubDirs
  28. FOR /D %%A IN (*.*) DO CALL :List "%%~A"
  29.  
  30. :: Done
  31. POPD
  32. GOTO End
  33.  
  34.  
  35. :List
  36. :: Set variable value to bytes used by directory
  37. FOR /F "tokens=3,4*" %%B IN ('DIR /A /-C /S "%~1" ^| FIND /I "File(s)"') DO SET ListDir=%%~B
  38. :: Add 0.5MB in order to properly round the value when integer divided by 1MB
  39. SET /A ListDir=%ListDir%+524288
  40. :: Integer divide by 1MB
  41. SET /A ListDir=%ListDir%/1048576
  42. :: Display resulting value in MB
  43. ECHO.%~1	%ListDir%
  44. :: Clear variable
  45. SET ListDir=
  46. GOTO:EOF
  47.  
  48.  
  49. :Syntax
  50. ECHO.
  51. ECHO DiskUse, Version 4.10 for Windows NT 4 / 2000 / XP
  52. ECHO Display disk space used by subdirectories (tab delimited)
  53. ECHO.
  54. ECHO Usage:  DISKUSE  [ startdir ]
  55. ECHO.
  56. ECHO Where:  "startdir"  is the directory containing subdirectories to be
  57. ECHO                     inventoried (default is the current directory)
  58. ECHO.
  59. ECHO Note:   Due to batch math limitations this batch file will return negative
  60. ECHO         numbers if the disk space used by subdirectories exceeds 2GB.
  61. ECHO         For Windows 2000/XP, upgrade to version 5 and use its /L switch.
  62. ECHO.
  63. ECHO Written by Rob van der Woude
  64. ECHO http://www.robvanderwoude.com
  65.  
  66. :End
  67. IF "%OS%"=="Windows_NT" ENDLOCAL
  68.