Search code examples
pythonpython-3.xlinuxdirectorydistro

How to access Linux's downloads folder using python?


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.


Solution

  • 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")
    

    Taken from this answer