![]() |
A program, or Perl script, which does regular expression-enhanced batch renaming.
Essential.
See also:
Usage and notes ∞
- Always test with
--nono - renumbering files
\rename 's/(.*?)\//$1append_this/' * --nono- How do I rename something to title-case?
-
\rename 's/\((\d)\)/00/' \(?\)--nono- will rename
(1)to001.
- will rename
-nor--nonois to make no changes.-
Some versions will let you do
rename <before> <after> <files>as with:rename "a string" "another string" *
Chopping off stuff ∞
It doesn't seem particularly possible to nuke a few characters off of the beginning. In Zsh I was able to do this:
for i in *; do \rename $i $i[7,-1] $i --nono ; done
Didn't work for stuff with spaces in them.. so use double-quotes I figure.. maybe something like this?:
for i in *; do \rename "$i" "$i[7,-1]" "$i" --nono ; done
Renaming with regular expressions ∞
\rename 's/\.htm$/\.html/' *.htm --nono \rename 's/(\w+)-(\w+)-(\d\d)-(\d{4})-NODATA.txt\$1.$4$3$2.log$//' * --nono \rename 'y/A-Z/a-z/' *.log --nono
Rename the first character ∞
- If the first character (
{1}) -
(Any character) (
.)- You can instead make it a number only (a "digit") (
\d)
- You can instead make it a number only (a "digit") (
- Then change that character to
8 - Take the rest of the filename (
(.*)) -
And append it to that
8($1)
\rename 's/.{1}(.*)$/8$1/' * --nono
Rename the first character using a variable ∞
As above, with different quoting:
REPLACE='hi' ; \rename "s/\d{1}(.*)$/$REPLACE\$1/" * --nono
- Notice that instead of single quotes (
'), this is using double-quotes (") -
Notice that
$1has become\$1.- This is because the example uses the double-quote (
") characters surrounding the expression
- This is because the example uses the double-quote (
Recursive, regular expression rename that respects spaces ∞
Tested and works. Also preserves .JPG if found in the middle of a filename. Unfortunately my version of "rename" doesn't allow regular expressions, so the rename isn't actually preserving. This gives horrid system lag which isn't helped by niceing.
0=$IFS ; IFS=$(echo -en "\n\b") ; for f in `find -regex '.*\.JPG$'`; do \rename .JPG .jpg "$f" --nono ; done ; IFS=$0
Without rename, see rename-files.sh
To only use builtins I'd have to be able to recurse using for loops.. (the "global" routine in 4DOS).
crazy stuff ∞
With Zsh..
See rename-files.sh
Alternatives ∞
-
Windows: PowerRename
Untested
(Perl) rename.pl ∞
(Perl)
-
Lacks a "dry run" switch, implemented as
-nelsewhere.
With Ruby ∞
(Ruby)
https://web.archive.org/web/20090303111310/http://snippets.dzone.com/posts/show/6249
Métamorphose ∞
2010-04-22 - (version not recorded)
2010-04-22 on Unity Linux 2010 rc1 64bit, updated 2010-02-15.
https://file-folder-ren.sourceforge.net/
smart install wxPythonGTK
seems to work well enough.. way too convoluted.
Renameutils ∞
-
http://www.nongnu.org/renameutils/
- commandline, should be good!
\smart-root install readline-devel
didn't get the hang of it..
Last updated 2024-07-01 at 15:10:04


ported
- decrufted
- pushed some scripts to git to workaround a blogtext bug
Added slightly more complex examples that I can't seem to keep in my memory.