1. 程式人生 > 其它 >python 下利用os模組建立目錄以及巧妙使用if not os.path.exits()建立

python 下利用os模組建立目錄以及巧妙使用if not os.path.exits()建立

一、單獨使用os.makedirs(path,mode=0o777)

import os

path='d\test'

os.makedirs(path,0755)

print('路徑被建立')

二,迴圈建立

path=base_path+'\'+"ciliylist[i]"

if not os.path.exists(path)

       os.makedirs(path)

file=open(path+'a.txt',w)

f.write('成功建立路徑')

file.close()