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;
}
 
-----Original Message-----
From: Earthlink-m_ryan [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 10, 2005 1:53 PM
To: Perl-Win32-Users@listserv.ActiveState.com
Subject: adding a title to a file on windows

Does anyone know how to add "Comments" to a file description from the command prompt?
 
I would like to change a list of files from long names to short names, but retain the descriptions in a field like "title" or "Comments".
 
file names are-
nvar_1234_Virginia_Jurisdictional_addendum.pdf
nvar_k1245_Regional_contract.pdf
and I want-
nvar_1234.pdf        -- with a description of "Virginia_Jurisdictional_addendum"
nvar_k1245.pdf      -- with a description of "Regional_contract"
 
Thank you in advance-
Matthew

 


This message was scanned by ATX
1:56:46 PM ET - 3/10/2005
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to