Dear Monks

May I assue that Tk chooseDirectory is faulty with Unicode paths on Windows?

My assumption is based on the following observation: on the same Windows 10 (Perl 5.26.1) machine the following scripts returns different paths. With getOpenFile and getSaveFile, the paths - even with unicode characters (chinese and so on) - are okay. I can use them to do things (open file, save it, etc.). The path returned by chooseDirectory is unusable (????). I read quite a lot about chooseDirectory and Unicode on this form, POD and so on. However, never found a working solution to get a usable path from chooseDirectory. Notice that my script has to work on potentially any Windows machine, irrespective of its way to encode paths. What do you think?

use Tk; use strict; use warnings; my $mw = MainWindow->new; my $menubar = $mw->Menu(-type => 'menubar'); $mw->configure(-menu => $menubar); my $mfile = $menubar->cascade(-label => '~File', -tearoff => 0); $mfile->command(-label => '~Open', -accelerator => 'Control+o', -command => \&open_file); $mfile->command(-label => '~Save', -accelerator => 'Control+s', -command => \&save_file); $mfile->command(-label => '~Select Dir', -accelerator => 'Control+d', -command => \&select_dir); my $exit = $mw->Button(-text => 'Exit', -command => [$mw => 'destroy']); $mw->bind('<Control-o>', [\&open_file]); $mw->bind('<Control-s>', [\&save_file]); $mw->bind('<Control-d>', [\&select_dir]); $exit->pack; my $types = [ ['Perl files', '.pl'], ['All Files', '*'],]; MainLoop; sub open_file { my $open = $mw->getOpenFile(-filetypes => $types, -defaultextension => '.pl'); print qq{You chose to open "$open"\n} if $open; } sub save_file { my $save = $mw->getSaveFile(-filetypes => $types, -initialfile => 'test', -defaultextension => '.pl'); print qq{You chose to save as "$save"\n} if $save; } sub select_dir { my $DirSelected = $mw->chooseDirectory(-initialdir => "~", -title +=> 'Choose directory to save your backup'); print qq{You chose to save as "$DirSelected"\n} if $DirSelected; }

Update

I just moved to a Chinese machine with a Chinese username. Well, here even getOpenFile/getSaveFile fail. Windows fires an error message saying that the path does not exist (with ??? in place of the user's name).


In reply to Tk unicode paths chooseDirectory vs getOpenFile and getSaveFile by Takamoto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.