Python - How do you select a folder?

   1739   1   0
User Avatar
Member
2 posts
Joined: Aug. 2012
Offline
Hi!

I'm working on a Python tool that allows users on Linux to search any folder they like for files containing a certain extension / keyword.

To do this, a dialog comes up asking them for a string of the folder location they'd like to search and a keyword to search for, like so -

start_popup = hou.ui.readMultiInput(start_message,
                                    ("Path to Search", "File to Look For"),
                                    initial_contents=(home_dir, ".exr"),
                                    title="File Finder",
                                    buttons=('OK', 'Cancel'),
                                    default_choice=0,
                                    close_choice=1)

I wanted to know if there was a way for the user to get a popup which is something like what hou.ui.selectFile() does, but for a folder instead?

That way I could use the output of the ‘selectFolder’ to populate the
'Path to Search' field and the user doesn't need to paste / type out the folder to search into.

Any help would be appreciated!
User Avatar
Member
2 posts
Joined: Aug. 2012
Offline
Solution -

There's a file_type option called “Directory” that does this. Must have missed it while I was looking through the docs -
hou.ui.selectFile(file_type=hou.fileType.Directory)
  • Quick Links