jon12 has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to get some clarity on Perl's ability to rename non-ascii files. I would like to rename only non-ascii files in a directory that contains ascii and non-ascii filenames.
System: Windows XP Pro
Is there a better way to achieve the renaming of files, as neither of these methods are effective?
Thanks in advance.
john
However, I am finding that with the standard Perl rename(oldfilename, newfilename) I recieve a "Permission Denied at <STDIN> line xxx" where xxx is the line containing the rename command. This error only appears when Perl attempts to rename a non-ascii filename.
Using the bactick rename: `rename \"oldfilename\" \"newfilename\"` the program seems to work with the caveat that Perl sees the non-ascii filenames as question marks ????? ????? and seems to find multiple duplicates and cannot rename all found. Error: Duplicate filename or file cannot be found.
Here is my code, I have many versions but this is my latest:
Build: Active Perl v5.8.4my $count = 1; print "Path to directory for renaming:\n"; chomp($dirname = <STDIN>); chdir $dirname or die "Cannot change to $dirname"; opendir(DIR, $dirname) or die "Cannot open $dirname"; while($myfile = readdir(DIR)) { $locate = telldir(DIR); if($myfile !~ m/[\?]+/gi) { print "$myfile: File is ascii\n"; } elsif($myfile =~ m/[\? ]+(\([0-9]+\))?\.(\w+)\i) #catches filenames + ???.txt or ????(2).txt { $count++; print "$myfile: File is non-ascii\n"; $ext = $2; $temp = "Non-Ascii_Filename_$count"; $newname = join "." $temp, $ext; rename($myfile, $newname) or warn $!; #rename \"$myfile\" \"$newname\"; #attempt with backtics } seekdir(DIR, $locate); } closedir(DIR);
System: Windows XP Pro
Is there a better way to achieve the renaming of files, as neither of these methods are effective?
Thanks in advance.
john
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Renaming non-ascii files
by halley (Prior) on Jun 01, 2005 at 13:10 UTC | |
Re: Renaming non-ascii files
by davidj (Priest) on Jun 01, 2005 at 11:41 UTC | |
| |
Re: Renaming non-ascii files
by SolidState (Scribe) on Jun 01, 2005 at 14:04 UTC | |
by Anonymous Monk on Jun 03, 2005 at 11:47 UTC | |
Re: Renaming non-ascii files
by kaif (Friar) on Jun 01, 2005 at 17:21 UTC | |
Re: Renaming non-ascii files
by thcsoft (Monk) on Jun 01, 2005 at 11:39 UTC | |
by doran (Deacon) on Jun 01, 2005 at 14:57 UTC |
Back to
Seekers of Perl Wisdom