Version 13 of tk_chooseDirectory

Updated 2012-09-15 18:28:35 by RLE

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


http://purl.org/tcl/home/man/tcl8.4/TkCmd/chooseDirectory.htm


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 - select


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?


MG Jan 21 2005 - In many apps on Windows that use a dialog similar to tk_chooseDirectory's, they have a button to create a new directory, when that's allowed. Apart from the addition of that button, though, it looks identical to tk_chooseDirectory; is this the same dialog from the MS Windows API? And if so, would it be possible to alter tk_chooseDirectory so that it shows the 'New' button, when -mustexist is false?


SEH -- 1/21/05 -- Is there a way to call tk_chooseDirectory explicitly on Windows in a manner equivalent to [::tk::dialog::file::] for tk_getOpenFile?