in reply to Wide characters in Windows filenames with File::Copy
use strict; use warnings; use autodie; use File::Copy; use utf8; use Encode qw(encode decode); use Test::More tests=>1; use File::Temp; use Win32; my $cp = "cp".Win32::GetACP(); # Update my $oldname = tmpnam(); open my $make, '>', $oldname; print $make "Any old thing\n"; close $make; #my $newname = encode('cp1252', "Hildur_Guđnadóttir.txt"); my $newname = encode($cp, "Hildur_Guđnadóttir.txt"); copy($oldname, $newname); unlink $oldname; opendir my $dh, '.'; my $readbackname; while (1) { $readbackname = readdir $dh; die "File not found\n" if !defined($readbackname); last if $readbackname =~ m/^Hildur_Gu.nad.+ttir\.+txt/; } #$readbackname = decode('cp1252', $readbackname); $readbackname = decode($cp, $readbackname); is($readbackname, $newname, 'round trip');
UPDATE: Corrected code per ikegami's comment Re^2: Wide characters in Windows filenames with File::Copy below.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Wide characters in Windows filenames with File::Copy
by ikegami (Patriarch) on Nov 21, 2023 at 03:26 UTC | |
|
Re^2: Wide characters in Windows filenames with File::Copy
by slugger415 (Monk) on Nov 21, 2023 at 04:24 UTC |