2

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?

Community
  • 1
  • 1
corvid
  • 10,733
  • 11
  • 61
  • 130

2 Answers2

2

This works on Mac, Linux, and Windows:

from pathlib import Path
path = Path.home() / "Pictures"
wim
  • 338,267
  • 99
  • 616
  • 750
  • Use `os.path.sep` instead of `/` – Ben Oct 28 '14 at 21:34
  • Oh, I didn't notice the "My" on windows... d'oh! – wim Oct 28 '14 at 21:36
  • 2
    @wim It may be a mistake in the question itself ;0 - on my Vista it's "Pictures", and on another machine with Windows 7 also. – BartoszKP Oct 28 '14 at 21:36
  • 1
    in contradiction to other systems on Linux the name could be different in different languages (MacOS and Windows make rename in the user interface). For example on my machine, it is `/home/useri/Obrazy`, where "Obrazy" is the translation of "Pictures" for Polish. – Grzegorz Bokota Oct 29 '21 at 08:21
0
from os import environ
import os.path

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