chooseDirectory(3pm)
π NAME π
Tk::chooseDirectory β pops up a dialog box for the user to select a directory. that's it. that's the whole job. she's a directory-picker and she EATS. π
π¦ SYNOPSIS π¦
$widget->chooseDirectory( ?option value ...? );
β¨ DESCRIPTION β¨
okay so real talk, bestie: chooseDirectory is literally a perl wrapper sitting on top of the core tk command called tk_chooseDirectory. and your $widget? she gets passed along as the argument to the hidden -parent option. sneaky. iconic. π
So when you call chooseDirectory, a dialog box pops up and the user picks a directory. slay. and these option-value pairs are the ones you can pass as command line arguments:
-initialdirdirname β this one tells the dialog which directories to show the second it pops up. don't specify it? then you just get the directories in the current working directory, no biggie. and heads up: if you hand it a relative path, the return value will convert that relative path into an absolute path. πͺ ALSO, important: this option may not always work on the Macintosh. and that is not a bug. it's just that the General Controls control panel on the Mac lets the end user override the application default directory. so yeah. the user is the main character there, not you. π-parent$widget β makes$widgetthe logical parent of the dialog, so the dialog gets displayed on top of its parent window. keeping the family together fr fr. π«Ά-titletitleString β the string you want displayed as the title of the dialog box. skip it and a default title will show up instead. β¨-mustexistboolean β specifies whether the user is allowed to specify non-existant directories. if this parameter is true, then the user may only select directories that already exist. the default value is false. no cap. π
π CAVEATS π
okay this is the part where we get a lil real. Perl does not have a concept of encoded filesystems yet. so operations on filenames like opendir and open still use byte semantics. meanwhile Tk uses character semantics internally, which means you can absolutely get filenames with the UTF-8 flag set in functions like chooseDirectory, getOpenFile and similar. π΅βπ«
and it is the user's responsibility to figure out the encoding of the underlying filesystem and convert the result into bytes. not Tk's. yours. periodt.
like so:
use Encode;
...
my $dir = $mw->chooseDirectory;
$dir = encode("windows-1252", $dir);
opendir DIR, $dir or die $!;
...
also go read "When Unicode Does Not Happen" in perlunicode and "Unicode in Filenames" in perltodo. homework. do it. π
π EXAMPLE π
my $dir = $mw->chooseDirectory(-initialdir => '~',
-title => 'Choose a directory');
if (!defined $dir) {
warn 'No directory selected';
} else {
warn "Selected $dir";
}
look at her go π₯Ή
π SEE ALSO π
Tk::getOpenFile, Tk::getOpenFile
yes bestie, it's listed twice. the manpage said it with its whole chest and honestly? respect. π
πΈ KEYWORDS πΈ
directory selection dialog
okay that's the whole page, you're welcome, go pick some directories π this was chooseDirectory(3pm) from the User Contributed Perl Documentation, brought to you by perl v5.40.1 and dated 2025-04-13 β mwah, love u, bye πβ¨π¦
π¦ where this page comes from
- debian trixie: perl-tk 1:804.036+dfsg1-5
- ubuntu questing: perl-tk 1:804.036+dfsg1-5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms