Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find path to desktop in python [duplicate]

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!

like image 775
exe Avatar asked Jun 07 '26 12:06

exe


2 Answers

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)
like image 198
Simdan Avatar answered Jun 10 '26 02:06

Simdan


You can do it by using os.environ mapping and add the Desktop path

import os
print(os.environ['USERPROFILE'] + '\Desktop')
like image 36
Andreas Avatar answered Jun 10 '26 01:06

Andreas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!