Saturday, July 21, 2018

python - How can i use enviroment variables like %homepath% to list files in a Directory

I want to use System variables to access certain directories without hardcoding the path.



Im Running Python 3.7 on a Windows 10 64 bit machine. The whole idea is, to later acess some executable files that exist in the desired directory.




import os
path = r'%homepath%/Desktop'
dirlist = os.listdir(path)
print(dirlist)



I expect the output to be a list of files on the desktop. What i get is an error message saying that the specified directory cannot be found. If i use the explizit path things work out just fine.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...