#!/usr/bin/perl -w # $Id$ # Yoni, 2.6.00 if ($#ARGV<2) { print STDERR<<EOM; rename file names using perl substitution: rename 'upper unless /^Make/' * rename 'lower unless /^Make/' * rename 'y/A-Z/a-z/ unless /^Make/' * (same as above) rename 's/\.orig\$//' *.orig rename '\$_ .= "-t"' * EOM exit(1); } $op = shift; $op =~ s|lower|y/A-Z/a-z/|; $op =~ s|upper|y/a-z/A-Z/|; for (@ARGV) { $was = $_; eval $op; $newnames{$_}++; $moveto{$was} = $_; } $ok=1; foreach (keys %newnames) { if ($newnames{$_}>1) { print STDERR "Multiple files ($newnames{$_}) would be renamed to $ +_\n"; $ok=0; } } exit 1 if(!$ok); foreach (keys %moveto) { next if ($_ eq$moveto{$_}); print "Renaming $_ to $moveto{$_}\n"; rename($_,$moveto{$_}); }
In reply to rename script by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |