Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python - Finding the user's "Downloads" folder

I already found this question that suggests to use os.path.expanduser(path) to get the user's home directory.

I would like to achieve the same with the "Downloads" folder. I know that this is possible in C#, yet I'm new to Python and don't know if this is possible here too, preferable platform-independent (Windows, Ubuntu).

I know that I just could do download_folder = os.path.expanduser("~")+"/Downloads/", yet (at least in Windows) it is possible to change the Default download folder.

like image 821
Markus Weninger Avatar asked Mar 07 '16 18:03

Markus Weninger


People also ask

How do I find the download directory in Python?

path. expanduser("~")+"/Downloads/" , yet (at least in Windows) it is possible to change the Default download folder. With sufficient ctypes-foo you could adapt the Windows-specific code in this answer to Python (with a fallback to os.

What is the directory for Downloads?

By default, Chrome, Firefox and Microsoft Edge download files to the Downloads folder located at %USERPROFILE%\Downloads. USERPROFILE is a variable that refers to the logged in user's profile directory on the Windows computer, e.g. the path may look like C:\Users\YourUserName\Downloads.

How do I find a folder path in Python?

To find out which directory in python you are currently in, use the getcwd() method. Cwd is for current working directory in python. This returns the path of the current python directory as a string in Python. To get it as a bytes object, we use the method getcwdb().

How do I change the directory for Python Downloads?

To change the current working directory in Python, use the chdir() method. The method accepts one argument, the path to the directory to which you want to change. The path argument can be absolute or relative.


1 Answers

from pathlib import Path downloads_path = str(Path.home() / "Downloads") 
like image 88
Shmidt Avatar answered Sep 29 '22 10:09

Shmidt