Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Renaming picture in folders...

by serf (Chaplain)
on Jan 04, 2006 at 14:57 UTC ( #520929=note: print w/ replies, xml ) Need Help??


in reply to Renaming picture in folders...

You don't say whether the progressive number is per folder or for the whole run - I've gone for per-folder here - if you want for the whole run then change the hash $num{$dir} to a scalar $num instead.

#!/usr/bin/perl use strict; use warnings; use File::Find; use File::Copy; # # Set this to 0 to turn off printing which files it's moving. # my $verbose = 1; my @dirs = qw( Folder_1 Folder_2 Folder_3 Folder_4 ); my %num; sub wanted { if ( -f $_ ) { my $dir = $File::Find::dir; $num{$dir}++; my $src = "$dir/$_"; my $target = "${dir}_$num{$dir}.jpg"; my $mv_msg = "move '$src' to '$dir/$target'"; if ( -f $target ) { die "Can't $mv_msg: File already exists!\n" } else { move( $_, $target ) || die "Can't $mv_msg: $!\n"; print "$mv_msg OK\n" if ($verbose); } } } File::Find::find( { wanted => \&wanted }, @dirs );
I'm also presuming here that you want them left in the same directory they were in - not moved up.


Comment on Re: Renaming picture in folders...
Select or Download Code
Re^2: Renaming picture in folders...
by A200560 (Novice) on Jan 04, 2006 at 17:41 UTC
    Thanks serf, very useful, I optimized (for SEO purposes) an images gallery of about 4000 images. Thanks and Happy New Year!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://520929]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2015-07-05 08:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (61 votes), past polls