C-Kermit 8.0.212 RENAME Command

As of: C-Kermit 8.0.212 Dev.18, Wed Apr 26 12:02:35 2006

The RENAME command normally has the form:

RENAME [ optional-switches ] sourcefile newname

where sourcefile names a single file and newname is the new name for it or, If source file contains wildcards, then newname must be the name of a directory, and in that case Kermit moves the source files to the given directory without changing their names.

Until now, only two switches were available:

RENAME /LIST
Display the old and new name for each file while renaming. Synonyms: /LOG, /VERBOSE

RENAME /NOLIST
Don't display the old and new name for each file while renaming. This is the default behavior. Synonyms: /NOLOG, /QUIET.

The three new switches, /UPPER, /LOWER, and /REPLACE, allow you to change the names of multiple files at once, and they take the place of the newname argument; i.e. when you give any of these switches, you can't also specify a new name.

RENAME /UPPER:{ALL,LOWER} and RENAME /LOWER:{ALL,UPPER} filespec
These switches let you change the alphabetic case of letters in filenames. For example, if you have a directory on Unix full of files with uppercase names, you can change them to lowercase with RENAME /LOWER *.

By default, all files that match the given filespec have their names changed (if necessary). This is what the ALL argument means, e.g.:

RENAME /LOWER:ALL *

(RENAME /LOWER is equivalent to RENAME /LOWER:ALL). The other argument (/LOWER:UPPER or /UPPER:LOWER) means to leave mixed-case filenames alone, and rename only those files whose names contain letters of only the given case.

Case conversion works reliably for ASCII characters only. Kermit uses the C library for this, which on any given platform might or might not handle non-ASCII letters, and if it does, then how it works would normally depend on your locale definitions (the LC_CTYPE and/or LANG environment variable). When non-ASCII letters are not handled by the C library, the RENAME command does change their case.

RENAME /REPLACE:{{String1}{String2}} filespec
The /REPLACE switch lets you change pieces of filenames by string substitution. String1 is the substring you want changed, and String2 is what you want to change it to. For example:

rename /replace:{{.jpeg}{.jpg}} *

changes all *.jpeg files to *.jpg.

A handy use for RENAME /REPLACE is to remove spaces from filenames, or to replace them with underscores:

rename /replace:{{ }{_}} *

By default, RENAME /REPLACE changes all occurrences of String1 in each filename to String2, so, for example, if you had a file called abcjpegxyz.jpeg, the command just shown would change its name to abcjpgxyz.jpg.

For greater control and flexibility, the /REPLACE: switch argument can take several distinct forms:

/REPLACE:String1
This means to remove all occurrences of String1 from the name. It is equivalent to /REPLACE:{{String1}{}}. Example: If a file was called "This_File_Has_A_Lot_Of_Underscrores_In_Its_Name on it, the result would be "ThisFileHasALotOfUnderscoresInItsName".

/REPLACE:{{String1}{String2}}
As already noted, this replaces every occurrence of String1 with String2 in each filename. Alphabetic case in string matching is done according to the current SET CASE setting.

/REPLACE:{{String1}{String2}{Options}}
Options can be included that add more control to the process. The option string is a sequence of characters; each character in the string is an option. The choices are:

  A: String matching is to be case-sensitive, regardless of SET CASE.
  a: String matching is to be case-independent, regardless of SET CASE.
  ^: String replacement will occur only at the beginning of the filename.
  $: String replacement will occur only at the end of the filename.
  1: Only the first occurrence of the string will be replaced.
  2: Only the second occurrence of the string will be replaced.
  ...
  9: Only the ninth occurrence of the string will be replaced.
  0: Only the final occurrence of the string will be replaced (same as -1).
  -: Before a digit: occurrences will be counted from the right.

Here are some examples showing how to use the /REPLACE options:

/REPLACE:{{foo}{bar}{^}} For all files whose names start with "foo", replaces the initial or only "foo" with "bar.

/REPLACE:{{}{New-}{^}} Prepends "New-" to the name of each file.

/REPLACE:{{.jpeg}{.jpg}{$}} Replaces ".jpeg" at the end of the filename with ".jpg".

/REPLACE:{{}{Old-}{$}} Appends "-Old" to the name of each file.

/REPLACE:{{foo}{bar}{A}} Replaces "foo", "FOO", "Foo", "fOO", etc, with "bar" in the filename.

/REPLACE:{{foo}{bar}{a}} Replaces only "foo" with "bar".

/REPLACE:{{a}{XX}} Changes every a to XX. For example a file called a.a.a.a would become XX.XX.XX.XX.

/REPLACE:{{a}{X}{2}} Changes only the second a to X. For example a file called a.a.a.a would become a.X.a.a.

/REPLACE:{{a}{X}{-1}} Changes only the final a in the filename (it doesn't have to be at the end) to X. For example a file called a.b.a.c.a.d would become a.b.a.c.X.d.

/REPLACE:{{foo}{NOTFOO}{-2}} Changes the second-to-last "foo" in the filename to "NOTFOO".

/REPLACE:{{foo}{}{-2}} Deletes the second-to-last "foo" from the filename.

Digits, ^, and $ are mutually contradictory. If you include more than one of these in the option string, only the last one is used. Similarly for 'a' and 'A':

/REPLACE:{{foo}{bar}{aA2$^}} This replaces "foo" with "bar" no matter what combination of upper and lower case letters are used in "foo" ('A' overrides 'a' in the option string), but only if "foo" is at the beginning of the filename ('^' overrides '$' and '2').

If you give an /UPPER or /LOWER switch and a /REPLACE switch in the same RENAME command, the /REPLACE action occurs first, then the case conversion.

Another option lets you change the encoding filenames. This is useful when filenames contain non-ASCII characters such as accented or non-Roman letters, and the names have been copied from another computer that uses a different encoding:

RENAME /CONVERT:charset1:charset2 Converts filenames from the first character set to the second one. The two character sets can be chosen from the SET FILE CHARACTER-SET list. For example suppose you have a file called "Olga_Tañón.txt" on a computer where ISO 8859-1 Latin Alphabet 1 is used, and you have transported it (e.g. on CDROM) to another computer where the text encoding is UTF8. Maybe you also have a lot of other files with similar names in the same directory. You can convert the filenames to UTF8 like this:

RENAME /CONVERT:latin1:utf8 *

Note: You should NOT use UCS2 for filenames since this encoding is not compatible with C strings used in Unix and elsewhere. Note 2: RENAME /CONVERT affects only the filename, not the file's contents. You can use the TRANSLATE command to convert the encoding of the contents of a text file.

RENAME /COLLISION:{FAIL,PROCEED,OVERWRITE} This switch governs Kermit's behavior when renaming multiple files, and any of the names would collide with the name of a file that already exists. The default, for compatibility with earlier releases of C-Kermit, is OVERWRITE, i.e. write over the existing file. The other two protect existing files. PROCEED means to skip (not rename) the file that would cause the collision, and proceed to the next file, if any. FAIL means that no files will be renamed if there would be any collisions; for this Kermit makes two passes, checking all the new names for existence before starting the second pass; however, there is no guarantee that in the second pass, it won't create the same new name for more than one file; in that case, it will stop before executing the second rename. You can use the new SET RENAME command to change Kermit's default collision action from OVERWRITE to FAIL or PROCEED.

RENAME /SIMULATE This switch can be used to see what the RENAME command would do without actually doing it. /SIMULATE implies /LIST.

You can change the following preferences for the RENAME command with the new SET RENAME command:

SET RENAME LIST { ON, OFF } Tells the RENAME command whether to list its actions if you don't include a /LIST or /NOLIST or equivalent switch.

SET RENAME COLLISION { FAIL, OVERWRITE, PROCEED } Tells the RENAME command how to handle filename collisions in the absence of a /COLLISION switch.

*** Add SHOW RENAME and HELP SET RENAME *** *** Add text to HELP RENAME ***


rename.html: 26 Apr 2006 12:03:27