Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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 :)

In reply to Re: Renaming non-ascii files by SolidState
in thread Renaming non-ascii files by jon12

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2023-05-30 10:15 GMT
Find Nodes?
    Voting Booth?

    No recent polls found