zoukankan      html  css  js  c++  java
  • python获取当前系统桌面路径

    一、用内置的winreg(推荐)

    import winreg
    def get_desktop():
        key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
                              r'SoftwareMicrosoftWindowsCurrentVersionExplorerShellFolders',)
        return winreg.QueryValueEx(key, "Desktop")[0]
    

    二、需要win32扩展

    import win32api,win32con
    def get_desktop():
        key =win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
                                  r'SoftwareMicrosoftWindowsCurrentVersionExplorerShellFolders',
                                 0,win32con.KEY_READ)
        return win32api.RegQueryValueEx(key,'Desktop')[0]
    

    三、需要win32扩展

    from win32com.shell import shell, shellcon
    def GetDesktopPath():
        ilist =shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_DESKTOP)
        return shell.SHGetPathFromIDList(ilist)
    

    四、内置的os

    import os
    def GetDesktopPath():
        return os.path.join(os.path.expanduser("~"), 'Desktop')
    

    该方法在用户改变了桌面路径后,会失效  

      

  • 相关阅读:
    假期学习总结2-14
    假期学习总结2-13
    假期总结2-12
    假期总结2-11
    读人月神话
    冲刺第五天 11.29 THU
    冲刺第四天 11.28 WED
    冲刺第三天 11.27 TUE
    冲刺第二天 11.26 MON
    冲刺第一天 11.23 FRI
  • 原文地址:https://www.cnblogs.com/hester/p/12092421.html
Copyright © 2011-2022 走看看