Tk
There are Tk commands that bring up the standard Windows style file browsers for selecting directories and files to open or save.
- tk_getOpenFile
- Opens a file browser to allow you to select an existing file.
- tk_getSaveFile
- Opens a file browser to allow you to either enter a new file name or select an existing file. If the file exists, you are prompted to overwrite the file.
- tk_chooseDirectory
- Opens a file browser to allow you to either enter a new directory name or select an existing directory.
There are additional options to these commands that allow for multiple file selection, initial directory specifications and file filtering, among others.
set filename [tk_getOpenFile];
puts "$filename";
Tcl returns the selected file name.
set filename [tk_getSaveFile];
puts "$filename";
Tcl returns the selected file name.
{{"File Description 1" *.ext1} {"File Description 2" *.ext2}};
set filetypes "{{OptiStruct files} {*.fem *.parm}} {{All Files} {*.*}}";
set filename [tk_getOpenFile -filetypes $filetypes];
puts $filename;
Tcl returns the selected file name.
set filename [tk_getOpenFile];
C:/My_files/readme.txt
file dirname $filename;
C:/My_files
file tail $filename;
readme.txt
file extension $filename;
.txt
file rootname $filename;
readme
set path_list [file split $filename];
C:/ My_files readme.txt
lindex $path_list end;
readme.txt