Created
November 19, 2018 15:49
-
-
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')
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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