DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Browse Windows File System And Get The Path

08.04.2005
| 10085 views |
  • submit to reddit
        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)