How to select a folder with native windows dialog box?

F

flaus.a

I found the win32ui.CreateFileDialog() function to select a file but
nothing to select a folder :'-(
Maybe someone has a solution for this?
Thanks!
 
R

Roger Upole

You can use SHBrowseForFolder:

from win32com.shell import shell
shell.SHBrowseForFolder()

Roger
 
F

flaus.a

Thanks for your answer, it's working fine!

For information, the function to use to get the pathName is
shell.SHGetPathFromIDList
It returns an error if you select a special folder (!?!?) but otherwise
it's working fine... And I was unable to fix this issue.
 
R

Roger Upole

Thanks for your answer, it's working fine!

For information, the function to use to get the pathName is
shell.SHGetPathFromIDList
It returns an error if you select a special folder (!?!?) but otherwise
it's working fine... And I was unable to fix this issue.

SHGetPathFromIDList only works for real filesystem folders.
Pseudo-folders like Control Panel or Network Connections
throw an error. You can use PyIShellFolder.BindToObject
to get an interface to perform operations on these.

Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top