1

In my linux python app for Fedora I want to save user's work to /home/user/Documents/MyCoolApp/TheirGreatWork.txt

But I am not sure how to find the "Documents" folder if the user is not using English as their default language.

What is the right way to determine the right path so that files go in their "Documents" folder.

EDIT

Here is a picture of a fedora dialog which comes up if you change locales... showing how paths can get easily changed.

jedierikb
  • 12,752
  • 22
  • 95
  • 166

2 Answers2

4

I'd use the subprocess module to get the output of the command xdg-user-dir DOCUMENTS. For example:

import subprocess
documents_dir = subprocess.check_output(["xdg-user-dir", "DOCUMENTS"])
print documents_dir  # This is what you're looking for.
arussell84
  • 2,443
  • 17
  • 18
  • 1
    note: subprocess.check_output requires Python 2.7. see http://stackoverflow.com/questions/2924310/whats-a-good-equivalent-to-pythons-subprocess-check-call-that-returns-the-conte#2924457 – FabienAndre Feb 10 '11 at 16:23
0

There is no right way as the user may have changed their locale, which (fortunately) does not rename the directory. If you want a fixed place for files managed by your app, use ~user/.MyCoolApp or let the user specify the directory.

Fred Foo
  • 355,277
  • 75
  • 744
  • 836