Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for chksize.rex

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

  1. /* ChkSize.rex,  Version 2.00 for OS/2 and Windows */
  2.  
  3. /* Display blank line */
  4. Say
  5.  
  6. /* Initialize RexxUtil */
  7. If RxFuncQuery( "SysLoadFuncs" ) <> 0 Then Do
  8. 	Call RxFuncAdd "sysloadfuncs", "RexxUtil", "sysloadfuncs"
  9. 	Call sysloadfuncs
  10. End
  11.  
  12. /* Read command line parameters */
  13. Parse Upper Arg commandline
  14.  
  15. /* Check parameters' validity */
  16. Parse Value commandline With '"'filespec'"' cmpsize dummy
  17. If filespec = "" Then Parse Value commandline With filespec cmpsize dummy
  18.  
  19. /* Check for the correct number of parameters */
  20. If dummy  <> "" Then Call Syntax
  21. If cmpsize = "" Then Call Syntax
  22.  
  23. /* Second parameter should be a whole number */
  24. If DataType( cmpsize, "W" ) <> 1 Then Call Syntax
  25.  
  26. /* Check if specified file exists */
  27. Call SysFileTree filespec, "files.", "F"
  28.  
  29. /* If it doesn't exist, or if wildcards were used, */
  30. /* or if a directory was specified, display help   */
  31. If files.0 <> 1 Then Call Syntax
  32. Parse Upper Value files.1 With . . actsize . file
  33. file = Strip( file )
  34. If FileSpec( "N", file ) <> FileSpec( "N", filespec ) Then Call Syntax
  35.  
  36. /* Compare actual and specified file size */
  37. Select
  38. 	When actsize = cmpsize Then Do
  39. 		say "Sizes match exactly"
  40. 		errorlevel = 0
  41. 	End
  42. 	When actsize > cmpsize Then Do
  43. 		say "Actual file size exceeds specified size"
  44. 		errorlevel = 1
  45. 	End
  46. 	When actsize < cmpsize Then Do
  47. 		say "Actual file size less than specified file size"
  48. 		errorlevel = 2
  49. 	End
  50. 	Otherwise errorlevel = 3
  51. End
  52.  
  53. /* Normal program termination, use errorlevel to return result */
  54. Exit errorlevel
  55.  
  56.  
  57. Syntax: Procedure
  58. 	Say "ChkSize,  Version 2.00 for OS/2 and Regina Rexx"
  59. 	Say "Checks if file size matches specified file size and returns an"
  60. 	Say "errorlevel accordingly"
  61. 	Say
  62. 	Say "Usage   :  CHKSIZE  <filespec>  <minimum_size>"
  63. 	Say
  64. 	Say "Returns :  Errorlevel 1 if greater than specified file size"
  65. 	Say "           Errorlevel 0 if equal to specified file size"
  66. 	Say "           Errorlevel 2 if smaller than specified file size"
  67. 	Say "           Errorlevel 3 if invalid parameters were specified"
  68. 	Say
  69. 	Say "Do not use wildcards in <filespec>."
  70. 	Say "<filespec> must be enclosed in double quotes if it contains spaces."
  71. 	Say
  72. 	Say "Written by Rob van der Woude"
  73. 	Say "http://www.robvanderwoude.com"
  74. 	Exit 3
  75. Return
  76.  

page last modified: 2024-04-16; loaded in 0.0210 seconds