http://qs1969.pair.com?node_id=462460


in reply to Renaming non-ascii files

Hi Jon12,
First of all, don't flame people that try to help you, or no one will want to help you. You got good advice about typos in your posted code. If the code you post is incorrect, it makes it harder for other people to help.

With that out of the way, I have to say I don't understand exactly the problems you are experiencing. Sometimes you refer to non-ascii files (contents are not ascii?) and sometimes to non-ascii filenames. So which is it?
I assume it is the filename, because that is what you seem to handle in your code. I'm not sure how to help, so I tried to simplify the code (so that it is easier to debug):

use strict; use warnings; my $count = 1; print "Path to directory for renaming:\n"; chomp(my $dirname = <STDIN>); chdir $dirname or die "Cannot change to $dirname"; opendir(DIR, $dirname) or die "Cannot open $dirname"; for my $myfile (grep {m/[^[:ascii:]]/} readdir(DIR)) { print "$myfile: Filename is non-ascii\n"; rename($myfile, "Non-Ascii_Filename_$count.txt") or warn $!; $count++; } closedir(DIR);

If this doesn't work, I'd like to hear how does a simple Perl "rename" of an ascii filename in the same directory and with the same permissions work.

If a simple ascii filename can be renamed without a problem, try doing "print for (readdir(DIR));" instead of the entire "for" loop in the above program. Look at how Perl treats the non-ascii filenames.

Other then that, I can only recommend trying out the File::Rename module from CPAN, psossibly it offers a more robust solution.

Good luck :)