home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rexxlb.zip / SAMPLES / DELCH.CMD < prev    next >
OS/2 REXX Batch file  |  1993-01-09  |  2KB  |  52 lines

  1. /*****************************************************************************/
  2. /*                                                                           */
  3. /* DELCH: Delete a file if CRCs compare.                                     */
  4. /*                                                                           */
  5. /* Requires Personal REXX or REXXLIB (parsefn, dosdrive, dosdel, filecrc     */
  6. /* functions).                                                               */
  7. /*                                                                           */
  8. /* Command format: DELCH <fileid1> <fileid2>                                 */
  9. /*                                                                           */
  10. /*      The first file is deleted if the CRCs match.                         */
  11. /*                                                                           */
  12. /*****************************************************************************/
  13.  
  14. parse arg file1 file2 .
  15. if file2 = '' then do
  16.     say 'Format is: DELCH <file1> <file2>'
  17.     exit 1
  18.     end
  19. parse value parsefn(file1) with disk1 path1 fn1 ft1
  20. parse value parsefn(file2) with disk2 path2 fn2 ft2
  21. if disk1 = '-' then
  22.     disk1 = dosdrive()
  23. if disk2 = '-' then
  24.     disk2 = disk1
  25. if fn2 = '-' & ft2 = '-' then do
  26.     fn2 = fn1
  27.     if ft1 \= '-' then
  28.         ft2 = ft1
  29.     end
  30. fileid1 = makefn(1)
  31. fileid2 = makefn(2)
  32. if filecrc(fileid1) = filecrc(fileid2) then do
  33.     say 'Files compare - deleting' fileid1
  34.     call dosdel fileid1
  35.     end
  36. else
  37.     say 'Files are different.'
  38. return
  39.  
  40. makefn:
  41. arg i
  42. path = value('path'i)
  43. if path = '-' then
  44.     path = ''
  45. fileid = value('disk'i)':'path
  46. ft = value('ft'i)
  47. if ft = '-' then
  48.     fileid = fileid||value('fn'i)
  49. else
  50.     fileid = fileid||value('fn'i)'.'ft
  51. return fileid
  52.