home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rexxlb.zip / SAMPLES / CMPDIR.CMD < prev    next >
OS/2 REXX Batch file  |  1993-02-05  |  4KB  |  139 lines

  1. /*****************************************************************************/
  2. /*                                                                           */
  3. /* CMPDIR: Compare date & time of all files in first directory to that of    */
  4. /* corresponding files in second directory, and show which files have        */
  5. /* earlier, later, or identical dates. First argument may also include a     */
  6. /* file name with wildcards.                                                 */
  7. /*                                                                           */
  8. /* Requires Personal REXX or REXXLIB (dosdrive, doscd, dosdir, dosdirpos,    */
  9. /* dosisdir, parsefn, upper functions).                                      */
  10. /*                                                                           */
  11. /* Command format: CMPDIR <filespec> <directory>                             */
  12. /*                                                                           */
  13. /*****************************************************************************/
  14.  
  15. parse arg dir1 dir2 .
  16. if dir1 = '' then do
  17.     say 'Disk or directory not specified.'
  18.     exit 1
  19.     end
  20. if dir2 = '' then
  21.     dir2 = dosdrive()':'doscd()
  22. if right(dir2, 1) = ':' then
  23.     dir2 = dir2||doscd(dir2)
  24. if \dosisdir(dir2) then do
  25.     say dir2 'not found.'
  26.     exit 2
  27.     end
  28.  
  29. parse value parsedname(dir1) with drive ',' path ',' fileid
  30. parse value parsedname(dir2) with drive2 ',' path2 ',' fileid2
  31.  
  32. dir1 = drive':'path
  33. dir2 = drive2':'path2
  34. fullid = dir1||fileid
  35. parse upper value fullid dir1 dir2 with fullid dir1 dir2
  36. file = dosdir(fullid)
  37. if file = '' then do
  38.     say 'Files "'fullid'" not found.'
  39.     exit 2
  40.     end
  41. newi = 0
  42. neweri = 0
  43. olderi = 0
  44. samei = 0
  45.  
  46. say 'Comparing' dir1 'with' dir2 '...'
  47. do while file \= ''
  48.     position = dosdirpos()
  49.     parse var file fname . fdate ftime .
  50.     newfile = dosdir(dir2||fname)
  51.     parse var newfile newfname . newfdate newftime .
  52.     comp = compdate(fdate ftime,newfdate newftime)
  53.     select
  54.         when newfile = '' then do
  55.             newi = newi + 1
  56.             new.newi = fname
  57.             end
  58.         when comp < 0 then do
  59.             olderi = olderi + 1
  60.             older.olderi = fname
  61.             end
  62.         when comp > 0 then do
  63.             neweri = neweri + 1
  64.             newer.neweri = fname
  65.             end
  66.         otherwise do
  67.             samei = samei + 1
  68.             same.samei = fname
  69.             end
  70.         end
  71.     file = dosdir(,,,,position)
  72.     end
  73.  
  74. sp = '     '
  75. if samei > 0 then do
  76.     say 'The following files have the same date:'
  77.     call show same, samei
  78.     end
  79. if olderi > 0 then do
  80.     say 'The following files are older on' dir1 'than on' dir2
  81.     call show older, olderi
  82.     end
  83. if neweri > 0 then do
  84.     say 'The following files are newer on' dir1 'than on' dir2
  85.     call show newer, neweri
  86.     end
  87. if newi > 0 then do
  88.     say 'The following files are on' dir1 'but not on' dir2
  89.     call show new, newi
  90.     end
  91. exit
  92.  
  93. /* compare two date-time paris */
  94. compdate: procedure
  95. parse arg mm1 '/' dd1 '/' yy1 time1, mm2 '/' dd2 '/' yy2 time2
  96. date1 = yy1||mm1||dd1||time1
  97. date2 = yy2||mm2||dd2||time2
  98. if date1 < date2 then
  99.     return -1
  100. else if date2 < date1
  101.     then return 1
  102. else
  103.     return 0
  104.  
  105. /* parse a file identifier */
  106. parsedname: procedure
  107. x = upper(arg(1))
  108. parsed = parsefn(x)
  109. if parsed = '' then
  110.     parsed = '- - - -'
  111. parse var parsed drive path fn ft
  112. if drive = '-' then
  113.     drive = dosdrive()
  114. if path = '-' then
  115.     path = doscd(drive)
  116. if right(path,1) \= '\' then
  117.     path = path'\'
  118. if fn = '-' then
  119.     fileid = '*.*'
  120. else if ft = '-' then
  121.     fileid = fn
  122. else
  123.     fileid = fn'.'ft
  124. return drive','path','fileid
  125.  
  126. /* display file names */
  127. show:
  128. line = ' '
  129. do x = 1 to arg(2)
  130.     line = line left(value(arg(1)'.x'), 14)
  131.     if x // 5 = 0 then do
  132.         say line
  133.         line = ' '
  134.         end
  135.     end
  136. if line \= '' then
  137.     say line
  138. return
  139.