in reply to Re^2: stat on file name containing single quotes
in thread stat on file name containing single quotes

Further testing indicates that we are getting side tracked by the single quote issue. That is if we change the input file so it specifies a file or directory name that contains extended ascii as in an accented e (0x82) then we get the same result with the stat function. Windows accepts these name. stat does not. The name I tested with came from my Adobe Acrobat installation in C:\Program Files (x86).

Here is the modified program run against an updated input file.

use 5.12.0; use strict; use warnings; use Carp; open IN,"<DirList2.txt"; my $fn=<IN>; chomp $fn; my @st=stat $fn; if (@st) { say "Array defined"; } else { say "Array undefined"; }

The input was:

C:\Program Files (x86)\Adobe\Acrobat 10.0\Acrobat\Sequences\FRA\Cr0xc20x82er des fichiers PDF accessibles.sequ

The output was:

Array undefined

Replies are listed 'Best First'.
Re^4: stat on file name containing single quotes ("A" vs "W")
by tye (Sage) on Jul 31, 2015 at 20:44 UTC

    Yeah, that can happen.

    Win32 supports single-byte-character API calls ("A") or UTF-16 API calls (called "UNICODE" or "W"). When using "A" calls, you can only represent characters in your defined "code page" (which then get converted to UTF-16 which is what is used by the underlying OS code).

    So either change your code page or use the "W" APIs. You'll have to do some searching to figure out what is the current state of getting access to the "W" APIs from Perl. I've seen several paths for doing such with different trade-offs but it has been so long since I've looked at that so I won't throw out my faded memory of out-dated info.

    - tye