Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

To add to link jahero provided, there's "language for non-Unicode programs" in Control Panel UI. If your paths use only characters belonging to the "code page" chosen there (as probably case of most people), try this:

use strict; use warnings; use feature 'say'; use utf8; use Win32; use Encode qw/ encode decode /; use File::Spec::Functions; my $parent = canonpath 'c:/Users/someuser/Documents'; my $folder = 'documentação'; my $path = catdir $parent, $folder; say Win32::GetACP; # 'ANSI Code Page' say Win32::GetOEMCP; # 'OEM Code Page' say 'ok' if -d encode('CP'. Win32::GetACP, $path); say 'ok' if decode('CP'. Win32::GetOEMCP, qx(dir $parent)) =~ /$folder +/;

Decode from OEMCP, what Windows commands return ('dir', etc.), if you ever need their output.

Decode from ACP what Perl's commands ('readdir', etc.) return. And encode to ACP, as above, to reach out from Perl and Unicode to Windows and "non-Unicode programs", e.g. with file tests, file access, copying, etc.

Things get more messy if your paths use characters outside of said "code page".

If I use opendir/readdir in the "c:\users\someuser\documents" directory it will read "documentação" perfectly

No. It's not Unicode string (no utf8 flag) it returns. It's encoded in 'ANSI Code Page'. That's why "-d will work fine".

Edit: minor clarifications. + P.S. So, first you encode to ACP an utf-8 path for argument to e.g. opendir, and then decode from ACP each element of readdir's return list, to work in Perl with normal Unicode strings.

P.P.S. Oh, dir $parent must be encoded, too, if non-ASCII characters are involved. Let it be an exercise to the reader, to which 'code page' :).


In reply to Re: Accent file names issue by vr
in thread Accent file names issue by ruimelo73

Title:
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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 09:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found