Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for filedate.rex

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

  1. /* FileDate,  Version 3.11                            */
  2. /* Cloned from the Norton Utilities for DOS           */
  3. /* Change date and time attributes of specified files */
  4. /* Written by Rob van der Woude                       */
  5. /* http://www.robvanderwoude.com                      */
  6.  
  7.  
  8. /* Initialize RexxUtil */
  9. If RxFuncQuery( "sysloadfuncs" ) <> 0 Then Do
  10. 	Call RxFuncAdd "sysloadfuncs", "RexxUtil", "sysloadfuncs"
  11. 	Call sysloadfuncs
  12. End
  13.  
  14. /* Defaults */
  15. filespec = "*.*"
  16. dateattr = ""
  17. timeattr = ""
  18. newdate  = ""
  19. newtime  = ""
  20.  
  21. /* Command line parsing */
  22. Parse Upper Arg parameters
  23. par.  = ""
  24. par.0 = 0
  25. Do i = 1 By 1 Until parameters = ""
  26. 	Parse Value parameters With par.i parameters
  27. 	par.0 = par.0 + 1
  28. End
  29. If par.0 > 1 Then Do i = 1 To par.0
  30. 	Select
  31. 		When Left( par.i, 2 ) = "/D" Then dateattr = SubStr( par.i, 3 )
  32. 		When Left( par.i, 2 ) = "/T" Then timeattr = SubStr( par.i, 3 )
  33. 		Otherwise filespec = par.i
  34. 	End
  35. End
  36. Else Do
  37. 	Call Syntax
  38. End
  39.  
  40. /* Either a new date or a new time or both should be specified */
  41. If dateattr||timeattr = "" Then Call Syntax
  42.  
  43. If dateattr <> "" Then Do
  44. 	If Length( dateattr )   < 6 Then Call Syntax
  45. 	If Pos( "-", dateattr ) > 0 Then Parse Value dateattr With dd"-"mm"-"yy
  46. 	If Pos( "/", dateattr ) > 0 Then Parse Value dateattr With dd"/"mm"/"yy
  47. 	If DataType( yy, "W" )  = 0 Then Call Syntax
  48. 	If DataType( mm, "W" )  = 0 Then Call Syntax
  49. 	If DataType( dd, "W" )  = 0 Then Call Syntax
  50. 	If yy < 100 Then yy = 2000 + yy
  51. 	If mm <  10 Then mm = Right( mm, 2, "0" )
  52. 	If dd <  10 Then dd = Right( dd, 2, "0" )
  53. 	newdate = yy||"-"||mm||"-"||dd
  54. End
  55.  
  56. If timeattr <> "" Then Do
  57. 	If Pos( ":", timeattr ) = 0 Then Call Syntax
  58. 	If Length( timeattr )  <  4 Then Call Syntax
  59. 	Parse Value timeattr With hh":"mn":"ss
  60. 	Select
  61. 		When Pos( "A", mn ) = 0 Then nop
  62. 		When Pos( "A", mn ) = 3 Then mm = left( mm, 2 )
  63. 		When Pos( "P", mn ) = 0 Then nop
  64. 		When Pos( "P", mn ) = 3 Then Do
  65. 			mm = left( mm, 2 )
  66. 			hh = hh + 12
  67. 		End
  68. 		Otherwise Call Syntax
  69. 	End
  70. 	If ss = "" Then ss = 0
  71. 	If DataType( hh, "W" ) = 0 Then Call Syntax
  72. 	If DataType( mn, "W" ) = 0 Then Call Syntax
  73. 	If DataType( ss, "W" ) = 0 Then Call Syntax
  74. 	If hh < 10 Then hh = Right( hh, 2, "0" )
  75. 	If mn < 10 Then mn = Right( mn, 2, "0" )
  76. 	If ss < 10 Then ss = Right( ss, 2, "0" )
  77. 	newtime = hh||":"||mn||":"||ss
  78. End
  79.  
  80. Call SysFileTree filespec, "file.", "FO"
  81. If file.0 = 0 Then Do
  82. 	Say "0D0A"X||"Invalid filespec or file not found"||"0D0A"X
  83. 	Call Syntax
  84. End
  85. Else Do i = 1 to file.0
  86. 	/* Retrieve old values for file date and time */
  87. 	Parse Value SysGetFileDateTime( file.i, "M" ) With olddate oldtime
  88. 	/* Set new values to old ones if not specified */
  89. 	If newdate = "" Then newdate = olddate
  90. 	If newtime = "" Then newtime = oldtime
  91. 	/* Set new values */
  92. 	Call SysSetFileDateTime file.i, newdate, newtime
  93. End
  94.  
  95. /* Normal program termination */
  96. Exit 0
  97.  
  98. Syntax:
  99. 	Say
  100. 	Say "FileDate,  Version 3.11 for Regina Rexx with RexxUtil"
  101. 	Say "Inspired by the Norton Utilities for DOS"
  102. 	Say "Change date and time attributes of specified files"
  103. 	Say
  104. 	Say "Usage:  FILEDATE.REX  [ filespec ]  /Ddd/mm/yy  /Thh:mm:ss"
  105. 	Say
  106. 	Say 'Where:                "filespec" is the specification of the file(s) to be'
  107. 	Say '                                 changed; wildcards allowed; default "*.*"'
  108. 	Say '                      "dd/mm/yy" is the new file date to be set'
  109. 	Say '                      "hh:mm:ss" is the new file time to be set'
  110. 	Say
  111. 	Say 
  112. 	Say "You may specify only a new file date or time, or both; the"
  113. 	Say "options not specified will not be changed."
  114. 	Say "The year may be specified in either 2 or 4 digits; if 2 digits"
  115. 	Say "are used, 2000 is added to the specified year."
  116. 	Say
  117. 	Say "Written by Rob van der Woude"
  118. 	Say "http://www.robvanderwoude.com"
  119. 	Exit 1
  120. Return
  121.  

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