判文件夹是否存在
import os
dirs = '/Users/joseph/work/python/'
if not os.path.exists(dirs):
os.makedirs(dirs)
判断文件是否存在,不存在则会新建
import osfilename = '/Users/joseph/work/python/poem.txt'
if not os.path.exists(filename):
os.system(r"touch {}".format(path))#调用系统命令行来创建文件
网友评论