|
|
use perl;
I wrote a similar Perl script for myself. Unlike Larry's, mine shows a list of changes that are to be made and prompts the users to confirm it's okay to proceed. When it comes to renaming files with Perl expressions, it's vital to see if your expression does what you think it does before it does it :-) (I often have to adjust the expression until I get it just right). Here's the script... #!/usr/bin/perl $expr = $ARGV[0]; @files = @ARGV[1..$#ARGV]; foreach (@files) { $old = $_; eval($expr); next if $_ eq $old; print "$old ==> $_n"; $RENAME{$old} = $_; } $|=1; print "Rename these ? "; if ( <STDIN> =~ /y/i) { foreach $f (keys %RENAME) { print STDERR "mv $f $RENAME{$f}n"; print STDERR `mv '$f' '$RENAME{$f}'`; } } else { print STDERR "Nothing renamedn"; } I also named the script "rename" and run it like this example: rename 's/.jpg/.jpeg/' *.jpg The output showing what will happen looks like this example: Fire_and_deer.jpg ==> Fire_and_deer.jpeg crash.jpg ==> crash.jpeg floods.jpg ==> floods.jpeg myrrh.jpg ==> myrrh.jpeg Rename these ?
Learning Perl
Of course the point of the advanced rename (thank you) is that it lets you check before committing, but just to be perlsnickety, with 's/.jpeg/.jpg/' you would get:
Learning Perl
You're right. There are various workarounds, if I was worried about mismatches I'd use 's/\.jpg$/.jpeg/'
use perl;
this doesn't seem to work right on files with spaces in their names, whereas Larry's did.
use perl; correction
sorry, it turns out only the feedback message is broken for files with spaces in their names. |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.09 seconds |
|