Version 7 of tk_chooseDirectory

Updated 2004-03-17 16:17:51

pops up a dialog box for the user to select a directory.


SYNOPSIS

tk_chooseDirectory ?option value ...?

DESCRIPTION

The procedure tk_chooseDirectory pops up a dialog box for the user to select a directory. The following option-value pairs are possible as command line arguments:

-initialdir dirname

Specifies that the directories in directory should be displayed when the dialog pops up. If this parameter is not specified, then the directories in the current working directory are displayed. If the parameter specifies a relative path, the return value will convert the relative path to an absolute path. This option may not always work on the Macintosh. This is not a bug. Rather, the General Controls control panel on the Mac allows the end user to override the application default directory.

-parent window

Makes window the logical parent of the dialog. The dialog is displayed on top of its parent window.

-title titleString

Specifies a string to display as the title of the dialog box. If this option is not specified, then a default title will be displayed.

-mustexist boolean

Specifies whether the user may specify non-existant directories. If this parameter is true, then the user may only select directories that already exist. The default value is false.

SEE ALSO

tk_getOpenFile, tk_getSaveFile


See also: chooseDirectory


No help from TclHelp on this (it's not in the index) - but we can get some help from Tk itself, by making a deliberate mistake in an interactive wish:

 % tk_chooseDirectory -help
 bad option "-help": must be -initialdir, -mustexist, -parent, or -title

Pops up a directory chooser (toplevel window). On Windows, using an old API - tree widget for a drive, and a drive selector below. On Unix (Tk 8.3), a selection widget (without drive selector).

Pauses execution until 'OK' or 'Cancel' have been selected. Returns the chosen pathname with canonical separators (slashes), or an empty string if canceled. Will on Windows not accept selection of mystic pathnames like

 C:\TEMP\axp426\{6F6549EC-8E14-11D3-BF1A-0060086F667D}

See http://www.purl.org/net/TclTkProgRef for Chris Nelson's tk_chooseDirectory written in pure Tcl.

A little more of a note on this util script: On Microsoft Windows 95 the tk_chooseDirectory fails. Apparently, a helper file or system dll is broken. Therefore, this script comes in real handy. It should also be noted that the tk_chooseDirectory function that comes with tcl/tk distribution is Windows only. So this file will be very helpful on your *nix or other platform computers. Another consideration should be taken with Windows 95. This script does not handle mapped drives. You may have to add that functionality yourself.

Note: tk_chooseDirectory was added to the UNIX Tk distribution in, I think, 8.3; it is an adaptation of the script in my site. -- CLN


Are there issues when choosing new vs existing directories?

Does this routine support the case where one wants to select a subdirectory of a not-yet existing directory?


Category Dialog - Category Command - Tk syntax help - Arts and Crafts of Tcl-Tk Programming