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.
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.
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.
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().
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.
from pathlib import Path downloads_path = str(Path.home() / "Downloads")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With