home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / ckscripts / changetype < prev    next >
Text File  |  2020-01-01  |  1KB  |  41 lines

  1. #!/usr/local/bin/kermit +
  2. #
  3. # c h a n g e t y p e
  4. #
  5. # Given a list of files, changes the filetype of each file whose filetype
  6. # matches argument \%1 to argument \%2.  Example:
  7. #
  8. #   changetype hlp txt *
  9. #
  10. # The third argument is a filename, a wildcard to match filenames, or
  11. # a list of files.  If it is omitted, all files in the current directory
  12. # are assumed.
  13. #
  14. # Illustrates:
  15. #  . Command-line argument interpretation
  16. #  . Array copying with offset
  17. #  . FOR loop consruction
  18. #  . Using \ffiles() to expand wildards and assign file list to an array
  19. #  . Using \fstripx() to remove the "filetype" part of a filename
  20. #  . RENAME command
  21. #
  22. # Author: F. da Cruz, The Kermit Project, Columbia University, July 1999
  23.  
  24. .\%n ::= \v(argc) - 1                    ; How many arguments on command line.
  25.  
  26. if ( < \%n 2 ) exit 1 {Usage: \fbasename(\%0) oldtype newtype [ filelist ]}
  27.  
  28. switch \%n {
  29.   :2, .\%n := \ffiles(*.\%1,&a), break   ; No args, do * in current directory.
  30.   :3, .\%n := \ffiles(\&_[3],&a), break  ; 1 arg, expand it.
  31.   :default                               ; More than 1 arg, use them literally.
  32.      array copy &_[3] &a[]
  33.      decrement \%n 2
  34. }
  35.  
  36. for \%i 1 \%n 1 {                        ; Loop through each file
  37.     if not match \&a[\%i] *.\%1 continue
  38.     rename /v \&a[\%i] \fstripx(\&a[\%i]).\%2
  39. }
  40. exit 0
  41.