For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2006 > Renaming pictures in folders....









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Renaming pictures in folders....
vincenzo.bacarella@gmail.com

2006-01-10, 4:02 am

I have a set of folders with some images in each.


Imaging this:


/Folder_1
/Folder_2
/Folder_3
/Folder_4
... . .


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 which
contains them.


How can I accomplish this with a fast Linux Perl script? Thanks for the

help.

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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com