Filenames examples:use Win32::OLE qw(in); use Encode; Win32::OLE->Option(CP => Win32::OLE::CP_UTF8); #Input: -dir to read files from #Output: -array ref with files sub ReadDirWithWin32OLE { my $dir = shift; #backslashes only in dir $dir=~s-\/-\\-g; #remove last backslash $dir=~s-\\\s*$--; if (not -e $dir) { warn "dir ($dir) does not exist"; return; } my $fso = Win32::OLE->new("Scripting.FileSystemObject"); #won't work if $dir contains unicode chars :( my $folder = $fso->GetFolder($dir); if (!$folder) { warn "Problem creating Win32::OLE (folder) object"; return; } my @filesFound = (); foreach my $file (in $folder->Files) { my $shortFilename = $file->ShortName; #my $shortFilename = $file->Name; $shortFilename = $dir . "\\" . $shortFilename; if (-e $shortFilename) { print "\nFile Found", $shortFilename; push @filesFound, $shortFilename; } else { print "\nFILE NOT FOUND!! (this should not happen):", $sho +rtFilename; } } return \@filesFound; }
BUT...:
1)If directory path ($dir) contains weird unicode chars it won't work?!
2)We're forced to use short filenames?! The Win32API::File trick, as mentioned by Corion, used here, didn't seem to work with "weird file2" (see above)?!
3)Still no way to open specific files with unicode chars if drag and dropped into a perl/tk window (but that is maybe whole different topic?).
@graff:
readdir gives us the ? char (ascii 63) instead of *any* weird unicode char.
In reply to Re^2: Opening files with japanese/chinese chars in filename
by Anonymous Monk
in thread Opening files with japanese/chinese chars in filename
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |