Select directory instead of file using system.file.saveFile

My application needs to prompt the user for a directory name. I would like to use system.file.saveFile(), or something like it, to open a browser which allows the user to select a directory/folder.

The problem is that saveFile() only wants to return file names. When you select a directory and press Save, the browser descends into that directory. The closest you can get is to type a non-existent name into the selection field. (Typing in an existing directory name again results in the browser descending into that directory.)

Iā€™m using an old version of Ignition (v. 7.5.10). If there is something I have overlooked in this version or a way to do this in a newer version, please let me know. Thanks.

Try this

from javax.swing import JFileChooser

chooser = JFileChooser()
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)
chooser.setAcceptAllFileFilterUsed(False)
chooser.setDialogTitle("Select Folder")
if chooser.showOpenDialog(None) == JFileChooser.APPROVE_OPTION:
	print str(chooser.getSelectedFile())
1 Like

Thank you! I had overlooked the Jython solution.