So I'm trying to make a specific program (in python) and when I use the path command and say I want to go to the desktop, it's in C:\Users\Myname\Desktop. And if someone else downloads the file it won't be able to path because I do not know the users name.
Asked
Active
Viewed 101 times
0
-
Could you give an example of your code which is accessing the file? – ConnerWithAnE Apr 09 '22 at 10:59
-
Do Note: That If You Use The Above Method You Need To Add A Check to see if a user has Linux Or Windows Operating Systems. – mrtechtroid Apr 09 '22 at 11:04
1 Answers
0
If you want just username
you can use this
os.environ["HOMEPATH"].split("\\")[-1]
# output: Afshar Sharifi
But if you want the whole path to desktop better to use thid
os.path.join(os.path.join(os.path.expanduser('~')), 'Desktop')
# output: C:\Users\Afshar Sharifi\Desktop

Afshar Sharifi
- 152
- 1
- 7
-
Thanks, just wondering how am I supposed to incorporate this into my code? – ASwedishMan Apr 09 '22 at 11:27