Skip to main content
 首页 » 编程设计

python之平台无关的方式来获取图片文件夹

2024年10月25日12sky-heaven

我正在尝试制作一些图像处理软件。在许多流行的操作系统上,都会有一个默认的图片文件夹。例如:

Mac: /User/corvid/Pictures/ 
Ubuntu: /home/corvid/Pictures/ 
Windows: C:\\user\\corvid\\My Pictures 

我知道一种基于 this question 使其适用于 Windows 的方法

from win32com.shell import shell, shellcon 
print shell.SHGetFolderPath(0, shellcon.CSIDL_MYPICTURES, None, 0) 

但是,有没有办法让它更通用一点?有没有办法以独立于平台的方式获取“图片”目录?

请您参考如下方法:

这适用于 Mac、Linux 和 Windows:

from pathlib import Path 
path = Path.home() / "Pictures"