First you need a hard-and-fast rule for converting the names. In your
example it would look like you want everything up to the last number in the
second "word" (where words are delimited by "_"). Also, is it safe to assume
they are all in the same directory? If that is the case, it could be something
like below (also assumes there is only one . in the
filename):
#UNTESTED
use strict;
use File::Copy; my $dir = '/somedir';
my %hash; opendir(DIR,$dir) || die "can't open $dir : $!\n"; my @files = readdir(DIR); closedir(DIR); foreach my $file (@files) { my ($name,$ext) = split(/\./,$file); my ($newname,$desc) = $name =~ /^(.*\d)_(.*)$/; $hash{$name}="$desc"; move("$file","$newname\.$ext"); } open(LOG,">> $log") || &outputerror; foreach my $key (keys %hash) { print LOG "$key -- with a description of $hash{$key}\n"; } sub outputerror
{ print "WARNING: Could not open log file for writing. THe following files were moved:\n\n"; foreach my $file (@files) { print "$file\n"; } exit 1;
}
|
_______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs