我正在尝试制作一些图像处理软件。在许多流行的操作系统上会有一个默认的图片文件夹。例如:
Mac: /User/corvid/Pictures/
Ubuntu: /home/corvid/Pictures/
Windows: C:\\user\\corvid\\My Pictures
我知道有一种方法可以让它适用于基于this question
的Windowsfrom win32com.shell import shell, shellcon
print shell.SHGetFolderPath(0, shellcon.CSIDL_MYPICTURES, None, 0)
但是,有没有办法让这更通用一点?有没有办法获取"图片"目录是否与平台无关?
答案 0 :(得分:2)
怎么样
from os.path import expanduser
folder = expanduser('~/Pictures')
不确定Windows,但您可以这样做:
if not os.path.isdir(folder):
# your already working windows way of getting it
答案 1 :(得分:0)
from os import environ
import os.path
pictures = os.path.join(environ["USERPROFILE"], "Pictures")