Hello all,

Sorry for this beginners question. I have many files which I want to rename
as follows: 

$src            =>      $dest

file01.jpg      =>      file01_01.jpg
file02.jpg      =>      file01_02.jpg
file03.jpg      =>      file01_03.jpg
file04a.jpg     =>      file01_04a.jpg
file04b.jpg     =>      file01_04b.jpg
file05.jpg      =>      file01_05.jpg
file06a.jpg     =>      file01_06a.jpg
file06b.jpg     =>      file01_06b.jpg
file06c.jpg     =>      file01_06c.jpg
file06d.jpg     =>      file01_06d.jpg
file07.jpg      =>      file01_07.jpg
file08.jpg      =>      file01_08.jpg
file09.jpg      =>      file01_09.jpg
file10.jpg      =>      file01_10.jpg
file11.jpg      =>      file01_11.jpg
file12.jpg      =>      file01_12.jpg
file13.jpg      =>      file02_01.jpg
file14.jpg      =>      file02_02.jpg
...
file24.jpg      =>      file02_12.jpg
file25.jpg      =>      file03_01.jpg



What I have so far is the following script :


#!/usr/bin/perl -w


use strict;
use warnings;


for my $src (@ARGV) {
    next unless $src =~ /^(file)(\d+[a-f]?)(\.jpg)$/i;
    my ($root, $nr, $ext) = ($1, $2, $3);
    next unless (($nr =~ /(d+)/) and ($1 > 12)) ; # here is my big problem !
        my $dest = lc ("$root" . "01_" . "$nr$ext");
        
        if(-e $dest) {
            warn "$dest already exists. Skipping ...\n";
            next;
        }
        print "Renaming would rename the following files \n
$src\t=>\t$dest\n";
    
#        rename $src, $dest
#            or warn "Failed to rename $src => $dest: $!";
} 

my problem, where I am stuck for the moment, is the test, whether the number
part of my original file name is of a certain amount :

next unless (($nr =~ /(d+)/) and ($1 > 12)) ;

better would be a test, whether $1 is between 1-12 or 13-24 or 25-36 ...

$src            =>          $dest

files1-12       =>          file01_
files13-24      =>          file02_
files25-36      =>          file03_


but there are files with extensions like 01a, 01b, 01c etc which count only
for one ! 


Could somebody be so kind and give my some help ?


Thank you



marek



-- 
______________________________________________________________________
___PODIUM_INTERNATIONAL_//_the_embassy_for_talented_young_musicians___
_______Marek_Stepanek__mstep_[at]_PodiumInternational_[dot]_org_______
__________________http://www.PodiumInternational.org__________________
______________________________________________________________________





                
___________________________________________________________ 
How much free photo storage do you get? Store your holiday 
snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com

Reply via email to