> -----Message d'origine-----
> De: Tomas Corral [mailto:[EMAIL PROTECTED]
> Date: mercredi 10 mars 2004 13:07
> À: [EMAIL PROTECTED]
> Objet: Change file names
> 
> 
> Hi all:
> 
> Because '@' is a special character for many interpreters. I'm 
> trying to
> change the names of 100 files deleting the '@' symbol. The filenames
> look like this:
> 
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> ....
> 
> Thanks in advance.
> 
> _:: A newbie ::_ 
> 
> 

Hi Tomas,

Try this little and simple script :

#!/usr/bin/perl -w

use strict;

open 'fh' ,'ls ./[EMAIL PROTECTED] |';  # create a file handle
my @file_list = (<fh>);
scalar (@file_list) or die "There is no file to change";

chomp(@file_list);

foreach my $file (@file_list) {
        print "renaming ". $file;
        my $new_file = $file; 
        $new_file =~ s/@/_ad_/; # change @ to '_ad_'
        $new_file =~ s/=/_equal_/;      
        print " to ".$new_file." ... "; 
        rename ($file, $new_file) ? print "OK \n" : print "NOK error_n on
$file, $new_file \n";
}


close 'fh';


hope this helps


Michel

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to