Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

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

I wouldn't rely on short names "on any desktop machine" -- 8.3 names could have easily been disabled on some of them. Besides, underlying MS API may be buggy, though I didn't investigate thoroughly. It seems that short name is not looked up (read from directory) if long name is itself 8.3 and uses CP1252 (? - not sure) characters.

E.g. my windows CP is not 1252 and doesn't contain "ñ" at all, therefore, for directory "Buñuel", "short" (actually, it's longer) name "BUUEL~1" is generated and must be supplied to non-complying software, such as Perl :).

D:\>mkdir Buñuel

D:\>dir /x
# skipped

21/11/2018  17:01    <DIR>          BUUEL~1      Buñuel

# skipped

Then I put "x.xlsx" into this directory, and:

use strict;
use warnings;
use feature 'say';
use utf8;
use Spreadsheet::ParseXLSX;
use Win32::API;
use Win32::LongPath;
use Encode qw/ encode decode /;
use Test::More;

Win32::API::More-> Import( 'kernel32', 'GetShortPathNameW', 'NPN', 'N' ) or die;

my $dir = 'D:\Buñuel';
my $tmp = encode 'UTF16LE', "$dir\0";
my $ptr = unpack 'L', pack 'p', $tmp;
my $buf = ' ' x 100;
my $len = GetShortPathNameW( $ptr, $buf, 100 ) or die;

my $short = substr +( decode 'UTF16LE', $buf ), 0, $len;

is $dir, $short,                "but they should not be the same!";
is shortpathL( $dir ), $short,  "because Win32 API is used anyway";

done_testing;

my $parser   = Spreadsheet::ParseXLSX-> new;
#my $workbook = $parser-> parse( shortpathL( "$dir/x.xlsx" ));   # will die here
my $workbook = $parser-> parse( 'D:\BUUEL~1/x.xlsx' );          # go on living

__END__

D:\>perl p.pl
ok 1 - but they should not be the same!
ok 2 - because Win32 API is used anyway
1..2

In reply to Re: Spreadsheet::ParseXLSX filename non Latin Tk getOpenFile by vr
in thread Spreadsheet::ParseXLSX filename non Latin Tk getOpenFile by IB2017

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 romping around the Monastery: (6)
As of 2024-04-19 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found