home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / fixtitle.zip / FixTitle.cmd next >
OS/2 REXX Batch file  |  1995-01-11  |  3KB  |  95 lines

  1. /* ============================================================= */
  2. /* REXX          FIXTITLE.CMD           M.H.Prager   Jan 95      */
  3. /* Change file titles to agree with names                        */
  4. /* ============================================================= */
  5. call RxFuncAdd SysLoadFuncs,RexxUtil,SysLoadFuncs
  6. call SysLoadFuncs
  7.  
  8. version = 1.01
  9.  
  10. /*--- Get filename to check & options from command line ---*/
  11. parse arg filename "-" option
  12. if filename="" then filename="*"
  13.  
  14. /*--- Turn options on and off ---*/
  15. option = translate(option)
  16. soption = 0     /* subdirectory option */
  17. hoption = 0     /* HELP option */
  18. yoption = 0     /* YES option */
  19. noption = 0     /* TELL option */
  20. if pos("S",option) ¬= 0 then soption = 1
  21. if pos("H",option) ¬= 0 then hoption = 1
  22. if pos("?",option) ¬= 0 then hoption = 1
  23. if pos("N",option) ¬= 0 then Noption = 1
  24.  
  25. /*--- Write banner to screen ---*/
  26. say ""; say "*** FIXTITLE version" version "***"
  27.  
  28. /*--- Process help option, if called by user, and quit ---*/
  29. if hoption then do
  30.    say ""; say "   Syntax is:  fixtitle [filename] [-[option...]]"
  31.    say ""; say "   where allowable options are:"; say ""
  32.    say "   H or ?   Print this help message"
  33.    say "   S        Process subdirectories"
  34.    say "   N        Don't process - just list files with nonmatching titles"
  35.    exit
  36. end
  37.  
  38. /*--- Load all the filenames into the variable PATH ---*/
  39. sftopts = 'BO'
  40. if soption then sftopts='BOS'
  41. call SysFileTree filename, 'path', sftopts
  42.  
  43. /*--- If no files, write message and exit ---*/
  44. if path.0 = 0 then do
  45.    say "*** No files found. Use 'fixtitle -h' for help."
  46.    exit
  47. end
  48.  
  49. /*--- Process all the files ---*/
  50. say ""; say "Examining" path.0 "file(s)...."
  51. nchange = 0
  52. ndiff = 0
  53. do i=1 to path.0
  54.    /* Extract the filename from the full path */
  55.    pos =lastpos("\",path.i) + 1
  56.    file.i = substr(path.i,pos)
  57.    /* Get the longname */
  58.    rc = SysGetEA(path.i, ".LONGNAME", "eainfo")
  59.    if rc = 0 then do
  60.       pos = lastpos("00"x,eainfo) + 1
  61.       longname = substr(eainfo,pos)
  62.    end
  63.    else longname = ""
  64.    /* say path.i "has longname" longname */
  65.    if longname ¬= "" & file.i ¬= longname then do
  66.       ndiff = ndiff + 1
  67.       if noption then do;
  68.          say " " path.i " has longname " longname "."
  69.          iterate;
  70.       end;
  71.       YN="";
  72.       do while yn ¬= "Y" & yn ¬= "N"
  73.          say ""
  74.          say "*** " path.i " has longname " longname ". Change longname?"
  75.          pull yn .
  76.       end
  77.       /*--- Write the new title to the extended attributes ---*/
  78.       if YN = "Y" then do
  79.          eainfo = "DFFF00000100FDFF"x || d2c(length(file.i))||"00"x||file.i
  80.          rc = SysPutEA(path.i, ".LONGNAME", eainfo)
  81.          if rc ¬= 0 then say "*** Could not change longname."
  82.          else nchange = nchange + 1
  83.          /* else say "*** Longname changed to" file.i ||"." */
  84.       end
  85.    end /* if */
  86. end
  87. say ""; say path.0 "file(s) examined."
  88. say ndiff "longname(s) did not match."
  89. say nchange "longname(s) changed."
  90. exit
  91. /* VERSION INFORMATION */
  92. /* 1.01   Added totals to end, banner, more comments. */
  93. /* ============================================================= */
  94.  
  95.