简体   繁体   English

独立于平台的方式来获取图片文件夹?

[英]platform-independent way to fetch pictures folder?

I am trying to make some image manipulation software.我正在尝试制作一些图像处理软件。 On many popular operating systems there would be a default picture folder.在许多流行的操作系统上,都会有一个默认的图片文件夹。 For example:例如:

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

I know of a way to make it work for windows based on this question我知道一种方法可以根据这个问题使其适用于 Windows

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

However, is there a way to make this a bit more generic?但是,有没有办法让它更通用一点? Is there a way to fetch the "Pictures" directory in a platform-independent way?有没有办法以独立于平台的方式获取“图片”目录?

How about怎么样

from os.path import expanduser
folder = expanduser('~/Pictures')

Not sure about windows, but you could then do:不确定窗户,但你可以这样做:

if not os.path.isdir(folder):
     # your already working windows way of getting it
from os import environ
import os.path

pictures = os.path.join(environ["USERPROFILE"], "Pictures")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM