In ubuntu the downloads folder is located in home\ubuntu\Downloads, but I don't know if different distros have the same "style" (eg. home\arch\Downloads). Is there a "universal path" for all distros? For anyone wondering i need to make a new directory in downloads.
Asked
Active
Viewed 683 times
1
-
Actually it is located under user's path. You can easily access it by `~/Downloads`, where `~` means user's home folder. YOu can get the absolute path of user's home directory in python. – MSH Dec 26 '21 at 19:46
-
I reopened the question because this [answers](https://stackoverflow.com/q/35851281/15239951) are not satisfactory in my opinion. `freedesktop` is never mentioned although it's a standard now under Linux. – Corralien Dec 26 '21 at 22:03
2 Answers
3
On Linux, you can use xdg-user-dir
from freedesktop.org project. It should work on every recent Desktop environments (KDE, Gnome, etc) and all recent distributions:
import shutil
import subprocess
xdg_bin = shutil.which('xdg-user-dir')
process = subprocess.run([xdg_bin, 'DOWNLOAD'], stdout=subprocess.PIPE)
download_path = process.stdout.strip().decode()
print(download_path)
# Output:
/home/corralien/Downloads
If you have Python 3.7 or higher, you can use the capture_output=True
argument instead of the stdout
argument.

Corralien
- 109,409
- 8
- 28
- 52
0
Your "home directory" (functionally similar to C:\Users\YOUR_USERNAME
on Windows) is at /home/YOUR_USERNAME
on most Linux distros, and this is where the Downloads folder is located usually. The way to be the most sure about getting the correct directory is by using pathlib.Path.home()
:
from pathlib import Path
downloads_path = str(Path.home() / "Downloads")

CoderCharmander
- 1,862
- 10
- 18
-
-
On some Linux distros, [including Ubuntu apparently](https://stackoverflow.com/questions/35851281/python-finding-the-users-downloads-folder/74231751#comment133999866_72591013) this directory name is localized into the OS install language or user's language (not sure which). – hippietrail Apr 12 '23 at 05:51