Finding the user's “My Documents” path

后端 未结 4 517
生来不讨喜
生来不讨喜 2020-11-28 11:14

I have this small program and it needs to create a small .txt file in their \'My Documents\' Folder. Here\'s the code I have for that:

textfile=open(\'C:\\Us         


        
4条回答
  •  被撕碎了的回忆
    2020-11-28 11:25

    You can use pywin32 extensions to access the Win32 API. With use of Win32 API you can get the virtual folder that represents the My Documents desktop item.

    from win32com.shell import shell, shellcon
    doc_folder = shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, None, 0)
    

    Here you can find the description of CSIDL_PERSONAL: https://docs.microsoft.com/en-us/windows/win32/shell/csidl

提交回复
热议问题