import os
folder = r"C:\Temp"
fname = "test.txt"
fpath = os.path.join(folder,fname)
print("file path:", fpath)
lis = fpath.split("\\")
#['C:', 'Temp', 'test.txt']
fpath2 = "\\".join(lis)
print("file path2:", fpath2)
folder2 = "\\".join(lis[0:-1])
print("folder2:", folder2)
“\\”.join([folder, fname]) #這樣也可以取代 os.path.join()
if not os.path.exists(ex_folder): os.makedirs(ex_folder):
C:\Temp 目錄底下新增了export 資料夾
推薦hahow線上學習python: https://igrape.net/30afN