fanticla has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

Probably my question has been already answered, but I didn't find any solution.

Here is the problem: Working on a Windows machine, how can I open a file if its path has characters with accents? I get the path using getOpenFile. Here is what I do.

sub convert_ansi_to_utf { my $types = [ ['Text', '.txt'], ['All Files', '*'],]; my $filename= $frame_kwic_setup->getOpenFile(-filetypes => $types); open(F, "<:encoding(iso-8859-1)", "$filename") or die $!; open(G, ">:utf8", "$filename.utf.txt") or die $!; while (<F>) { print G } close (F); close (G); }

It is a simple subrutine to convert a textfile from ANSI to UTF-8. If the path is for example:

C:\Documents and Settings\AA\Documents\Data\Examples\Università\AS 2010\text.txt

I get an error, file could not be found. Anyone has an Idea how to solve the problem? Thanks. C.

Replies are listed 'Best First'.
Re: dos path accents
by Anonymous Monk on Oct 22, 2010 at 08:32 UTC

      Thank you!

      I still like to use getOpenFile, as it offers a fine TK funtionality to select files in Windows. I changed my subrutine a little bit adding Win32::GetShortPathName() as you suggested. It works fine now. Here is the new script:

      sub convert_ansi_to_utf { my $types = [ ['Text', '.txt'], ['All Files', '*'],]; my $filename= $frame_kwic_setup->getOpenFile(-filetypes => $types); use Win32; my $shortpath = Win32::GetShortPathName( "$filename" ); open(F, "<:encoding(iso-8859-1)", "$shortpath") or die $!; open(G, ">:utf8", "$shortpath.utf.txt") or die $!; while (<F>) { print G } close (F); close (G); }