(dired.info)Renaming and More With Regexps

Next: Other File Creating Commands Prev: Copy and Move Into a Directory Up: Mark-using Commands

Renaming (and More) With Regexps

   A second class of Commands uses regular expressions to construct a
new filename from each marked file. Note: Syntax of Regular
Expressions.  The commands to make new names by regexp
conversion are the same as those to make them in another directory,
except that they share a prefix char, `%'.

     (`dired-rename-regexp') Rename files with regexps

     (`dired-do-copy-regexp') Copy files with regexps.

     (`dired-do-hardlink-regexp') Make hard links with regexps.

     (`dired-do-symlink-regexp') Make symbolic links with regexps.

   These commands prompt in the minibuffer for a REGEXP and a NEWNAME.
For each marked file matching REGEXP, a new filename is constructed
from NEWNAME.  The match can be anywhere in the file name, it need not
span the whole filename.  Use `^' and `$' to anchor matches that should
span the whole filename.  Only the first match in the filename is
replaced with NEWTEXT.  (It would be easy to change this to replace all
matches, but probably harder to use.)

   `\&' in NEWNAME stands for the entire text being replaced.  `\D' in
NEWNAME, where D is a digit, stands for whatever matched the D'th
parenthesized grouping in REGEXP.  As each match is found, the user
must type a character saying whether or not to apply the command to
just this file (`y' or `n') or to all remaining files(`!').  For help
type your help character, usually `C-h', at that time.

   For example, if you want to rename all `.lsp' files to `.el' files,
type first `%m' with `\.lsp$' as regexp to mark all `.lsp' files.  Then
type `%r' with `\.lsp$' and `.el' as REGEXP and NEWTEXT arguments.
Dired will prompt you for each file to be renamed.

   Or to append `.old' to all marked files, use `%r' `$' `RET' `.old'
`RET', replacing the empty string at the end of each file name with

   You can use the regexp `\(.+\)\.\(.+\)$' to make the basename as
`\1' and the extension as `\2' available in NEWTEXT.

   With a zero prefix arg, renaming by regexp affects the complete
pathname.  Usually only the non-directory part of file names is used and
changed, and renaming only takes place within the current directory.
The zero prefix argument can be used to change the directory part as

   Often you will want to apply the command to all files matching the
same REGEXP that you use in the command.  Simply use the `%m' command
with REGEXP as argument, which will then also be the default for the
next regexp using command. For example, to remove a `V17I12-' prefix
from several filenames, use `%m' `^V17I12-' `RET' `%r' `RET' `RET', in
effect replacing the prefix with the empy string.

automatically generated by info2www