I need to save a folder called D:\MyPc if the hostname is MyPc
name_file = open("D:/Others/name.txt" , "r") data = name_file.readline() name_file.close() print(os.path.join("D:\", data)) the output is D:
MyPc
To check the hostname: How can I use Python to get the system hostname?
Also, there is an error in your code. Change the last line to have double backslash in string:
print(os.path.join("D:\\", data))
data? I'm surprised that"D:\"parsed, but ifdatais a fully qualified path name, the join won't change it.datato something that we can test. The code you post will raise a syntax error and I don't see any way that it could produce the output shown.