一,用内置的winreg(推荐)

import winreg
def get_desktop():
    key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,\
                          r'Software\Microsoft\Windows\CurrentVersion\Explorer\ShellFolders',)
    return winreg.QueryValueEx(key, "Desktop")[0]

二,需要win32扩展

import win32api,win32con
def get_desktop():
    key =win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,\
                              r'Software\Microsoft\Windows\CurrentVersion\Explorer\ShellFolders',\
                             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')

python获取当前系统的桌面的路径的更多相关文章

  1. python,winreg,获取当前系统的桌面绝对路径

    import winreg import os def main(): new_path = os.path.join(desktop_path(), 'aaa.xlsx') # 结果为:C:\\Us ...

  2. Python获取当前系统时间

    Python获取当前系统时间 import time #返回当前时间 def GetNowTime():     return time.strftime("%Y-%m-%d %H:%M:% ...

  3. C# - 获取windows系统特殊文件夹路径

    一.路径分类 1.绝对路径 完整路径,从磁盘符号开始,如:C:\Windows 2.相对路径 以当前路径为起点,不包含磁盘符号,通常使用“..\”符号来访问上级目录中的文件或文件夹. ../Windo ...

  4. 使用Python获取Linux系统的各种信息

    哪个Python版本? 当我提及Python,所指的就是CPython 2(准确的是2.7).我会显式提醒那些相同的代码在CPython 3 (3.3)上是不工作的,以及提供一份解释不同之处的备选代码 ...

  5. (26)Python获取某个文件存放的相对路径(更改任意目录下保持不变)

    import os import platform def getSeparator(): ''' 获取不同平台下的斜杠符号 :return: Created by Wu Yongcong 2017- ...

  6. 转:python获取linux系统及性能信息

    原文:http://amitsaha.github.io/site/notes/articles/python_linux/article.html In this article, we will ...

  7. 【转】Python获取当前系统时间

    转自:https://www.cnblogs.com/-ldzwzj-1991/p/5889629.html 取得时间相关的信息的话,要用到python time模块,python time模块里面有 ...

  8. [python]获取当前路径用来构造相对路径的几种方法

    print('getcwd', os.getcwd()) print('sysargv', sys.argv) print('realpath', os.path.realpath(sys.argv[ ...

  9. 【C#】获取当前系统桌面、我的照片、我的文档等路径

    获取当前系统桌面.我的照片.我的文档等路径   using System; using System.Collections.Generic; using System.ComponentModel; ...

随机推荐

  1. ASP.NET配置文件Web.config 详细解释

    一.认识Web.config文件 Web.config文件是一个XML文本文件,它用来储存 ASP.NET Web 应用程序的配置信息(如最常用的设置ASP.NET Web 应用程序的身份验证方式), ...

  2. 手写简化版printf函数

    2019.02.01更新:经同学提醒,myprintf函数应有返回值为输出的字符数. 期末的大作业,手写一个myprintf函数,支持如下一些操作. 也就是  % -(负号控制左右对齐) 数(控制字段 ...

  3. C语言入门教程-(4)常量和变量

    1.常量和变量的概念 程序执行过程中其值不能发生改变的量叫做常量,其值能发生改变的量叫做变量.常量可以直接使用,而变量则必须先定义后才能使用,否则编译器会报错. 2.常量和变量的命名规范 在介绍常量和 ...

  4. Python练习-无参装饰器的正确打开方式

    import time def DecoUserPrint(UserFunc):#定义一个DecoUserPrint接收参数的多重方法 def DecoPrint(): StartTime = tim ...

  5. httpd.conf详解,因为php始终报fileinfo扩展无法加载的错

    # # This is the main Apache HTTP server configuration file. It contains the # configuration directiv ...

  6. oracle 修改属性

    alter table 表名 modify 字段名 类型; alter table 表名 modify 字段名 属性名; alter table TEST modify sbirthday not n ...

  7. javascript中用闭包递归遍历树状数组

    做公司项目时,要求写一个方法,方法的参数为一个菜单数组集合和一个菜单id,菜单数组的格式为树状json,如下面所示: [{"id":28,"text":&quo ...

  8. DirectFB简介以及移植[一]【转】

    转自:https://blog.csdn.net/wavemcu/article/details/39251805 ****************************************** ...

  9. 006_Mac下sublime text 的“package control”安装,sublimepackage

    Mac下sublime text 的“package control”安装,sublimepackage 小伙伴们好,我根据昨晚的经历写一个小总结:关于“Mac下sublime text 的“pack ...

  10. 二、springcloud之熔断器hystrix

    一.背景 雪崩效应 在微服务架构中通常会有多个服务层调用,基础服务的故障可能会导致级联故障,进而造成整个系统不可用的情况,这种现象被称为服务雪崩效应.服务雪崩效应是一种因“服务提供者”的不可用导致“服 ...