Python Gets the Windows special folder path

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.