Sometimes you want to add desktop shortcuts to your program, but even the exact path of the desktop do not know, fortunately, Microsoft's API gives some special folder path acquisition method, and then use the Python win32com module (non-standard library) can be used in Python to achieve the same operation!
#-*-coding:cp936-*-from win32com.shell import shellfrom Win32com.shell import shellcon# Get the "Startup" folder path, the key is the last parameter Csidl_ STARTUP, these parameters can be found in Microsoft's official documentation Startup_path = Shell. SHGetPathFromIDList (shell. SHGetSpecialFolderLocation (0,shellcon. Csidl_startup)) #获取 the "desktop" folder path, change the last parameter to csidl_desktop Desktop_path = Shell. SHGetPathFromIDList (shell. SHGetSpecialFolderLocation (0,shellcon. csidl_desktop)) If __name__ = = "__main__": print startup_path print Desktop_path
Csidl the corresponding table of the parameters and folders, see the official Microsoft documentation, http://msdn.microsoft.com/en-us/library/bb762494 (v=vs.85). aspx
Python Gets the Windows special folder path