FileChooser to select a directory, not a file

My code processes all the files in a folder in a Windows window. I want to offer the user (who will also be me) the opportunity to select a folder for processing using the standard file selection dialog.

I am trying to use the GetOpenFileName function to make this happen. (I actually call it from Python via pywin32 , but this should not be relevant.)

I can make him select a specific file, but I do not see any parameters allowing the user to select a folder instead.

Is there a combination of flags that I didn't understand, do I call the wrong function completely or is there another idiom for this?

+4
source share
2 answers

Unfortunately, I think you are calling the wrong function entirely. It has been a while since I made Win32 gui stuff .. but I seem to remember that there is another way to create a "select directory" window. This was not a direct Win32 function, but some API shell function that required a whole bunch of code to do the simplest thing.

Update. A little google reveals the SHBrowseForFolder function.

Update two: and here is an example for Python .

+4
source

As Greg points out, the function you want is a shell function. The SHBrowseForFolder function you SHBrowseForFolder , which is pretty messy for a call. There is also PyWin32 documentation for it that mentions the browse_for_folder.py sample.

+2
source

All Articles