perl -e '
use File::Find;
my $dir = "/top/level/directory/here";
find(\&rename_files, $dir);
sub rename_files {
if ($File::Find::name =~ /category040/) {
$oldfile = $File::Find::name;
$File::Find::name =~ s/category040/category080/;
`mv $oldfile $File::Find::name`;
}
}'
#!/bin/bash
for file in *;do
newfile=$(echo $file | sed s/category040/category080/g)
test "$file" != "$newfile" && mv "$file" $newfile
done
# Store $File::Find::name in both $oldfile and $newfile
$oldfile = $newfile = $File::Find::name;
$newfile =~ s/category040/category080/;
`mv $oldfile $newfile`;
find . *category040* | grep category040 | perl -p -e 's/^(.*)(category040)(.*$)/mv $1$2$3 $1category080$3/' | sh$ renamer --helpusage: renamer [OPTION]... [FILE]...options: --version show program's version number and exit -h, --help show this help message and exit Filename modifications: -R STR, --remove=STR remove STR -F OLD NEW, --fixed-string=OLD NEW change OLD to NEW -P PATTERN NEW, --perl-regexp=PATTERN NEW change regexp /PATTERN/ to NEW Miscellaneous: -r, --recursive recurse through subdirectories -d, --directories rename directories as well -n, --dry-run don't actually do anythingIf you have Python 2.4 and will use it, I'll package it up and put it on the web for you.
find . -name "*80*" -exec bash -c "mv \$1 \`echo \$1 | sed s/80/40/\`" -- {} \;
on preview - i don't know why, but i need to invoke bash again (what i posted didn't work for me with cygwin bash)renamer --recursive --fixed-string 80 40 is? ;)perl -MFile::Find -e 'find(sub {if (-f and /category040/) { $old = $_; s/category040/category080/g; rename $old, $_}}, ".")'
-f $_ with (-f or -l).
find, but life's too short to work out how (or i'm too stupid). what i do is usefindto produce a list of files in a temp file, then emacs (which you can "program") to turn that list into a list of "mv" commands.so, in this case, it would be something like:
find . -name "*80*" -print > tmp
emacs tmp
*stuff involve ^X^(... *
source tmp
of course, if the emacs stuff above is gibberish, this won't help. sorry.
posted by andrew cooke at 7:44 AM on March 17, 2005