python获取当前桌面的路径

参考链接:xinyangq

 

import winreg
import os

# 合并路径与文件名
def main():
    new_path = os.path.join(desktop_path(), 'aaa.xlsx') 
    print(new_path)

# 获取当前系统的桌面绝对路径
def desktop_path():
    key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders')
    path = winreg.QueryValueEx(key, "Desktop")[0]
    return path

if __name__ == '__main__':
    pp = desktop_path()
    print(pp)
    main()

 

你可能感兴趣的:(python获取当前桌面的路径)