| usenet@DavidFilmer.com 2006-01-10, 4:02 am |
| vincenzo.bacarella@gmail.com wrote:
> Imaging this:
>
> /Folder_1
> /Folder_2
>
> Now, each of those directories has images called with names like
> "475849.jpg" I want to get everyone of those "475849.jpg" recursively
> and rename their with names like Folder_x_y where the y is a
> progressive number and "Folder_x" is the name of the folder
LOOK OUT! Here comes David Filmer waving his IO::All banner! Be
careful - he might hit you with some Perl code that shows how wonderful
the IO::All module is, and how it solves all your IO problems!
OH NO - IT'S TOO LATE - He's already written the code!!!
#!/usr/bin/perl
use strict; use warnings;
use IO::All;
my $root_dir = '/tmp/test/clpm';
my %count;
foreach my $file( io($root_dir) -> all_files(0) ) {
my ($dir) = ($file =~ m!^.*/(.*)/!);
$count { $dir }++;
io($file) -> rename ("${dir}_$count{$dir}");
}
__END__
--
http://DavidFilmer.com
|