I am new to the os library and I was wondering how I could find the path for any user who uses windows and access their desktop directory using python. Thanks in advance!
Previous solutions won't work if the Desktop folder was manually changed by the user (to a OneDrive folder or whatever...).
This will work:
from win32com.shell import shell, shellcon
desktop = shell.SHGetFolderPath (0, shellcon.CSIDL_DESKTOP, 0, 0)
You can do it by using os.environ mapping and add the Desktop path
import os
print(os.environ['USERPROFILE'] + '\Desktop')
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