Skip to content

Instantly share code, notes, and snippets.

@bthaman
Created November 19, 2018 15:49
Show Gist options
  • Save bthaman/64b20ef47b2364b16c2c6bc529b1d451 to your computer and use it in GitHub Desktop.
Save bthaman/64b20ef47b2364b16c2c6bc529b1d451 to your computer and use it in GitHub Desktop.
Python function that returns the download path for the current user in Windows or Linux (e.g., 'C:\Users\username\Downloads')
import os
def get_download_path():
"""Returns the default downloads path for linux or windows"""
if os.name == 'nt':
import winreg
sub_key = r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'
downloads_guid = '{374DE290-123F-4565-9164-39C4925E467B}'
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, sub_key) as key:
location = winreg.QueryValueEx(key, downloads_guid)[0]
return location
else:
return os.path.join(os.path.expanduser('~'), 'downloads')
if __name__ == '__main__':
print(get_download_path())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment