How to get Windows’ special folders for currently logged-in user?

Should you wish to do it without the win32 extensions, you can use ctypes to call SHGetFolderPath:

>>> import ctypes.wintypes
>>> CSIDL_PERSONAL= 5       # My Documents
>>> SHGFP_TYPE_CURRENT= 0   # Want current, not default value

>>> buf= ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
>>> ctypes.windll.shell32.SHGetFolderPathW(0, CSIDL_PERSONAL, 0, SHGFP_TYPE_CURRENT, buf)
0
>>> buf.value
u'C:\\Documents and Settings\\User\\My Documents'

Leave a Comment