(emacs)Transforming File Names
Next: Comparison in Dired Prev: Shell Commands in Dired Up: Dired
Transforming File Names in Dired
Here are commands that alter file names in a systematic way:
Rename each of the selected files to an upper case name
(`dired-upcase'). If the old file names are `Foo' and `bar', the
new names are `FOO' and `BAR'.
Rename each of the selected files to a lower case name
(`dired-downcase'). If the old file names are `Foo' and `bar',
the new names are `foo' and `bar'.
`% R FROM RET TO RET'
`% C FROM RET TO RET'
`% H FROM RET TO RET'
`% S FROM RET TO RET'
These four commands rename, copy, make hard links and make soft
links, in each case computing the new name by regular expression
substitution from the name of the old file.
The four regular expression substitution commands effectively perform
`query-replace-regexp' on the selected file names in the Dired buffer.
They read two arguments: a regular expression FROM, and a substitution
The commands match each "old" file name against the regular
expression FROM, and then replace the matching part with TO. You can
use `\&' and `\DIGIT' in TO to refer to all or part of the old file
name, as in `query-replace' (Note: Query Replace.).
For example, `% R ^.*$ RET x-\& RET' renames each selected file by
prepending `x-' to its name. The inverse of this, removing `x-' from
the front of each file name, is also possible: one method is `% R
^x-.*$ RET \& RET'; another is `% R ^x- RET RET'. (Use `^' and `$' to
anchor matches that should span the whole filename.)
If the regular expression matches more than once in a file name, only
the first match is replaced.
Normally, the replacement process does not consider the files'
directory names; it operates on the file name within the directory. If
you specify a prefix argument of zero, then replacement affects the
entire absolute file name including directory name.
Often you will want to apply the command to all files matching the
same REGEXP that you use in the command. To do this, mark those files
with `% m REGEXP RET', then use the same regular expression in the
command to operate on the files. To make this easier, the commands to
operate use the last regular expression specified in a `%' command as a
automatically generated by info2www