Browse Windows File System And Get The Path
Join the DZone community and get the full member experience.Join For Free
This will show a "Browse For Folder" dialog, which doesn't return the path to the folder (some of the folders are "special", and as such don't have a path). The second call returns the full path from the PIDL (an identifier for the chosen folder). This call will throw a COM error if a "special" folder is chosen, so be sure to wrap in a try/catch clause. SHBrowseForFolder can be called with no args (), which will give you no dialog message.
from win32com.shell import shell pidl,disp,imglist=shell.SHBrowseForFolder(0,None,"Please choose a directory. Thanks.") fullpath=shell.SHGetPathFromIDList(pidl)
Opinions expressed by DZone contributors are their own.