1

I'm working on a Python script that needs to access files in the user's Downloads folder. However, I'm having trouble finding a reliable way to get the path to the Downloads folder that works regardless of the language version of Windows (e.g. English, Polish etc.). Is there a built-in function or module in Python that can help with this?

I've tried using the os.path.expanduser("~") method to get the path to the user's home directory, and then appending "Downloads" to it. However, this doesn't work on non-English versions of Windows since the name of the Downloads folder can be different (e.g. "Pobrane" in Polish).

Any help or advice would be greatly appreciated. Thanks in advance!

SoSaymon
  • 11
  • 3
  • you sure about that? mine is in Spanish (win 10), so is called "Descargas" but that is only like an alias or something, the true name is still "Downloads", thus `os.path.exists(os.path.join(os.path.expanduser("~"),"Downloads"))==True` and `os.path.exists(os.path.join(os.path.expanduser("~"),"Descargas"))==False` – Copperfield Mar 21 '23 at 23:27

2 Answers2

4

You could use the build in module winreg for this.

Then get the downloads folder from the registry which is

{374DE290-123F-4565-9164-39C4925E467B}

The full code would look like this:

import winreg
import os

reg_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")

downloads_path = winreg.QueryValueEx(reg_key, "{374DE290-123F-4565-9164-39C4925E467B}")[0]

winreg.CloseKey(reg_key)

print(downloads_path)

This will work on Windows 7 and later.

Datertec
  • 163
  • 4
  • Just a little addition, as of this day, on Windows 10, the above registry will get you the path to the Downloads folder. If you want to go inside that folder concat `"\\"` or `"/"` to the `downloads_path` variable. – ARHAM RUMI Aug 03 '23 at 10:50
0

To obtain the full path to the downloads folder on any version of Windows, you can use the command "shell: Downloads" which will lead you to the folder. From there, you can take the parent directory of the resulting path, which will provide you with the complete and accurate path to the downloads folder, regardless of the language used in the operating system.