How do I open folder selection dialog in Perl?
Asked
Active
Viewed 3,545 times
3
-
Which GUI toolkit are you using? (Tk, Win32::GUI, wxPerl, etc.) – Michael Carman Dec 09 '09 at 03:16
-
Voting to close as "not a real question" since Greg doesn't seem to be willing to give us any more information. – innaM Dec 09 '09 at 10:14
-
@Manni: That may be so, but this can still be a useful question, as there are now answer examples for Tk and Win32::GUI ... – Adam Bellaire Dec 09 '09 at 13:14
-
I suspect he doesn't have any GUI toolkit yet. – Ether Dec 09 '09 at 16:48
3 Answers
7
Depends on the GUI system you're using, and perhaps the platform. For example, on Windows and using Win32::GUI
, you can use GetOpenFileName
:
# $main is your main window...
$my_file = $main->GetOpenFileName(
-title => 'Select a file...',
-file => 'default.file',
);

Adam Bellaire
- 108,003
- 19
- 148
- 163
7
Most portable (at least compared to others):
use Tk;
my $dir = Tk::MainWindow->new->chooseDirectory;
Of course, if you're actually using Tk in the rest of your program, you should call chooseDirectory
on a proper parent widget instead of the one constructed and destructed here.

ephemient
- 198,619
- 38
- 280
- 391