home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / renqwk.zip / RENQWK.CMD < prev    next >
OS/2 REXX Batch file  |  1993-11-06  |  4KB  |  139 lines

  1. /* renqwk.cmd -- renames .QWK files based on the date that they were DL'd,
  2. along with a user-determined BBS prefix
  3.  
  4. Steve Allen
  5. Altech Computer Services
  6. 121 Herta St.
  7. Easley, SC 29640
  8.  
  9. Nov 93
  10. */
  11.  
  12. say ""
  13. say "RENQWK v1.0 1993"
  14. say "Altech Computer Services" 'fe'x "Steve Allen"
  15. say ""
  16.  
  17. call RxFuncAdd SysLoadFuncs,RexxUtil,SysLoadFuncs
  18. call SysLoadFuncs
  19.  
  20. main: 
  21.     NbrRenamed = 0
  22.     call GetConfig
  23.     Filespec = QwkDir"\*.*"
  24.     call SysFileTree Filespec, FileList,'F'
  25.     do i=1 to FileList.0
  26.         parse var FileList.i Date Time Size Attr FullFileName
  27.         if ValidExt(FullFileName) then
  28.             call RenameFile FullFileName Date
  29.         else
  30.             iterate
  31.     end
  32.     say ""
  33.     say NbrRenamed "QWK packets renamed."
  34. exit
  35.  
  36.  
  37. ValidExt: procedure
  38. arg FullFileName
  39.     RetVal = 0
  40.     parse var FullFileName . "." Ext
  41.     FileName = NameWOPath(FullFileName)
  42.  
  43.     /* if this QWK packet has already been renamed, we don't rename it again */
  44.     if substr(Ext,1,2) = "QW" &,
  45.         (datatype(substr(FileName,1,2),"M") &, 
  46.          datatype(substr(FileName,3,6),"W")) then
  47.             nop
  48.     else
  49.         if substr(Ext,1,2) = "QW" | (datatype(substr(Ext,1,1),"W"),
  50.             & length(Ext) = 1) then
  51.                 RetVal = 1
  52. return RetVal
  53.  
  54.  
  55. RenameFile: procedure expose Extension. NbrRenamed
  56. arg FullFileName Date
  57.     Date = right(Date,8)
  58.     Date = translate(Date,"0"," ")
  59.     parse var Date MM "/" DD "/" YY
  60.     FileName = NameWOPath(FullFilename)
  61.     DateName = FilePrefix(FileName) || YY || MM || DD || ".QWK"
  62.     PathName = PathPart(FullFileName)
  63.     NewFile = CreateNewName(DateName, PathName)
  64.     say "Renaming" FullFileName "to" NewFile"..."
  65.     "@REN" FullFileName NewFile "> NUL"
  66.     NbrRenamed = NbrRenamed + 1
  67. return 
  68.  
  69.  
  70. CreateNewName: procedure
  71. arg DateName, PathName
  72.     WholeName = PathName || DateName
  73.     CheckExists = stream(WholeName, 'c', 'query exists')
  74.     if CheckExists <> "" then 
  75.         do i = 1 to 9
  76.             DateName = substr(DateName,1,11) || i
  77.             WholeName = PathName || DateName
  78.             CheckExists = stream(WholeName, 'c', 'query exists')
  79.             if CheckExists = "" then leave
  80.         end
  81. return DateName
  82.  
  83.  
  84. NameWOPath: procedure
  85. arg FullFilename
  86.     StartPos = lastpos("\", FullFileName) + 1
  87.     OrigFilename = substr(FullFileName, StartPos)
  88. return OrigFilename
  89.  
  90.  
  91. PathPart: procedure
  92. arg FullFilename
  93.     EndPos = lastpos("\", FullFileName) 
  94.     PathName = substr(FullFileName, 1, EndPos)
  95. return PathName
  96.  
  97.  
  98. GetConfig: procedure expose Extension. QwkDir
  99.     Share = "OS2ENVIRONMENT"
  100.     CmdDir = value('CmdDir',,Share)
  101.     if CmdDir = "" then
  102.         Ifile = "RENQWK.CFG"
  103.     else
  104.         Ifile = CmdDir"\RENQWK.CFG"
  105.  
  106.     Iline = linein(Ifile)
  107.     QwkDir = strip(Iline)
  108.  
  109.     i = 0
  110.     do while lines(Ifile) > 0
  111.         Iline = linein(Ifile)
  112.         if Iline <> "" then
  113.             do
  114.                 parse var Iline BBS "=" BBSprefix .
  115.                 i = i + 1
  116.                 Extension.i.1 = strip(BBS)
  117.                 Extension.i.2 = strip(BBSprefix)
  118.             end
  119.     end
  120.     Extension.0 = i
  121. return
  122.  
  123.  
  124. FilePrefix: procedure expose Extension.
  125. arg BBSName
  126.     parse var BBSName BaseName "."
  127.     do i = 1 to Extension.0
  128.         if BaseName = extension.i.1 then leave
  129.     end
  130.  
  131.     if i > Extension.0 then
  132.         Prefix = "UN"
  133.     else
  134.         Prefix = Extension.i.2
  135. return Prefix
  136.  
  137.  
  138. /* end of RENQWK.CMD */
  139.