Powered by GeSHi

Source code for chksize.bat

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

  1. @ECHO OFF
  2. :: Check validity of command line parameters:
  3. :: *** 2 command line parameters needed
  4. IF [%2]==[] GOTO Syntax
  5. :: *** second parameter should be a number greater than 0
  6. IF %2 LSS 0 GOTO Syntax
  7. :: ** first parameter must be a valid file specification
  8. IF NOT EXIST %1 GOTO Syntax
  9. :: *** first parameter must be a file name, not a directory
  10. DIR /A-D /B %~nx1 2>NUL | FIND /I "%~nx1" >NUL
  11. IF ERRORLEVEL 1 GOTO Syntax
  12. :: *** no wildcards allowed in file specification
  13. ECHO.%* | FIND "*" >NUL
  14. IF NOT ERRORLEVEL 1 GOTO Syntax
  15. ECHO.%* | FIND "?" >NUL
  16. IF NOT ERRORLEVEL 1 GOTO Syntax
  17.  
  18. :: Keep variables local
  19. SETLOCAL
  20. :: Second parameter is the specified minimum file size
  21. SET CMPSIZE=%2
  22. :: Remove delimiters from file size; adjust if not used in US version of NT
  23. SET CMPSIZE=%CMPSIZE:,=%
  24. :: Check specified file's actual size
  25. FOR /F "tokens=3* delims= " %%A IN ('DIR %1 /-C /N ^| FIND /I "%~nx1"') DO SET ACTSIZE=%%A
  26. :: Compare file size to specified minimum size and display result
  27. IF %CMPSIZE% EQU %ACTSIZE% ECHO Sizes match exactly
  28. IF %CMPSIZE% LSS %ACTSIZE% ECHO Actual file size exceeds specified size
  29. IF %CMPSIZE% GTR %ACTSIZE% ECHO Actual file size less than specified file size
  30. :: Set an errorlevel if actual file size is less than specified minimum
  31. IF %CMPSIZE% LEQ %ACTSIZE% COLOR 00
  32. ENDLOCAL
  33. GOTO:EOF
  34.  
  35. :Syntax
  36. ECHO.>CON
  37. ECHO ChkSize,  Version 1.00 for Windows NT 4>CON
  38. ECHO Checks if file size matches specified file>CON
  39. ECHO size and returns an errorlevel accordingly>CON
  40. ECHO Restriction:>CON
  41. ECHO will not handle sizes over 2GB correctly>CON
  42. ECHO.>CON
  43. ECHO Written by Rob van der Woude>CON
  44. ECHO http://www.robvanderwoude.com>CON
  45. ECHO.>CON
  46. (ECHO Usage   :  CHKSIZE  ^<filespec^>  ^<minimum_size^>)>CON
  47. ECHO.>CON
  48. ECHO Returns :  Errorlevel 0 if greater than or equal to specified file size>CON
  49. ECHO            Errorlevel 1 if smaller than specified file size>CON
  50. ECHO.>CON
  51. (ECHO Do not use wildcards in ^<filespec^>)>CON
  52. ECHO ^<filespec^> must be enclosed in double quotes if it contains spaces>CON
  53. GOTO:EOF
  54.