判斷目錄是否存在
import os dirs = '/Users/joseph/work/python/' if not os.path.exists(dirs): os.makedirs(dirs)
判斷文件是否存在
import os filename = '/Users/joseph/work/python/poem.txt' if not os.path.exists(filename): os.system(r"touch {}".format(path))#調用系統命令行來創建文件