简体   繁体   中英

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

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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