home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / CHGCAS.ZIP / CHGCASE.CMD
OS/2 REXX Batch file  |  1991-08-06  |  3KB  |  89 lines

  1. /* Steve Price IBM SAA REXX Development Department, Aug. 2, 1991
  2. ** CompuServe: 70312,1612
  3. ** Internet:   pricesg@gdlvm7
  4. ** Phone:      (607) 752-1866
  5. ** Mail:       G09/21A, IBM Corp., P.O. Box 6, Endicott NY 13760
  6.  
  7. ** (C) Copyright IBM Corporation, 1991
  8.  
  9. ** Program to rename files to upper or lower case.
  10. ** Lower is default.
  11.  
  12. ** Will work on individual files or groups of files.
  13.  
  14. ** Syntax: chgcase fileid [/Lower|/Upper]
  15.  
  16. ** NOTE:  HPFS supports lower-case file names, but FAT does not.
  17. ** This program will appear to work on FAT (no error messages),
  18. ** but the filenames will not change.
  19.  
  20. ** NOTE:  This program is not NLS enabled:  it will only
  21. ** translate between uppper and lower case for the 26
  22. ** letters used in the English alphabet.
  23.  
  24. */
  25.  
  26. Parse arg fileid '/'opt
  27. If fileid = '' then Do
  28.    Say 'CHGCASE:  Error, filename is required.'
  29.    Exit 4
  30. end  /* Do */
  31.  
  32. Select             /* Decide which way we are translating.         */
  33.                    /* The first test will succeed for opt = ''     */
  34.                    /* as well as opt being any substring of LOWER  */
  35.   When abbrev('LOWER', translate(opt)) then Do
  36.     input_table = xrange('A','Z')
  37.     output_table= xrange('a','z')
  38.     end  /* Do */
  39.   When abbrev('UPPER', translate(opt)) then Do
  40.     input_table = xrange('a','z')
  41.     output_table= xrange('A','Z')
  42.     end  /* Do */
  43.   Otherwise
  44.     Say 'CHGCASE:  Error detected (unknown option).'
  45.     Say 'valid options are LOWER and UPPER.  your option was "'opt'"'
  46.     Exit 8
  47. End
  48.  
  49. /* Now we have our translate tables.                               */
  50. /* Next we decide if we are doing one file, or more than one.      */
  51.  
  52. If Pos('*',fileid) > 0 | Pos('?',fileid) > 0 Then Do
  53.   /* Call DIR to find all the files.  We pipe the result in to    */
  54.   /* a REXX queue.  We create a new queue to guard against the    */
  55.   /* possiblity of another process using the queue while          */
  56.   /* we are using it.                                             */
  57.   qname = Rxqueue('create')
  58.   oldq = Rxqueue('set',qname)
  59.  
  60.   '@DIR' fileid '/F|RXQUEUE' qname
  61.   If rc <> 0 Then Do
  62.     Say 'CHGCASE: some problem on the DIR command, rc='rc
  63.     Exit 12
  64.   End  /* Do */
  65.  
  66.   Do Queued()
  67.      /* Now process each file and directoyr that DIR found for us.*/
  68.      Parse Pull oname
  69.      Parse Value Reverse(oname) With oname '\' .
  70.      oname = Reverse(oname)
  71.      if oname = '' | oname = '.' | oname = '..' then iterate
  72.  
  73.      'RENAME' oname translate(oname, output_table, input_table)
  74.      If rc <> 0 Then
  75.        Say 'CHGCASE: some problem on the RENAME command for',
  76.          oname', rc=' rc
  77.   End /* do Queued() */
  78.   Call Rxqueue 'Delete',qname
  79.  
  80. End /* fileid has an * or ? in it */
  81. Else Do /* This is the simple case of just a single file.          */
  82.   'RENAME' fileid translate(fileid, output_table, input_table)
  83.   If rc <> 0 Then Do
  84.     Say 'CHGCASE: some problem on the RENAME command, rc=' rc
  85.     Exit 20
  86.   End  /* Do if rc <>  */
  87.  
  88. Exit
  89.