Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileChooser to select a directory, not a file

My code processes all the files in a folder on a Windows box. I want to offer the user (who happens to also be me) the option to select the folder to be processed, using the standard File Chooser dialog.

I am trying to use the GetOpenFileName function to make this happen. (I am actually calling it from Python via pywin32, but that shouldn't be relevant.)

I can get it to select a particular file, but I can't see any options to let the user select a folder instead.

Is there a flag combination I haven't understood, am I calling the wrong function entirely or is there another idiom for doing this?

like image 930
Oddthinking Avatar asked Jan 25 '23 00:01

Oddthinking


2 Answers

Unfortunately, I think you're calling the wrong function entirely. It's been a while since I've done Win32 gui stuff.. but I seem to recall that there was a different way of bringing up a "select directory" box. It wasn't a straight Win32 function, but was some shell API function that required a whole heap of code to do the simplest thing.

Update: A bit of google reveals the SHBrowseForFolder function.

Update two: And here is an example for Python.

like image 95
Greg Hewgill Avatar answered Mar 27 '23 13:03

Greg Hewgill


As Greg mentions, the function you want is a shell function. The specific function you need is SHBrowseForFolder, which is pretty messy to call. There's also PyWin32 documentation for it which mentions the browse_for_folder.py sample.

like image 41
Martin Kenny Avatar answered Mar 27 '23 13:03

Martin Kenny