def mkdir(path):
isExists = os.path.exists(path)
if not isExists:
os.makedirs(path)
print('Directory create successfully!')
return True
else:
print('Directory already exists!')
return False
save_dir = 'D:/Project_QF/Amyloid_search/data/potential/amyloid_structure/'
mkdir(save_dir)
或者直接使用系统函数
判断目录是否存在import os
dirs = 'D:/Project_QF/Amyloid_search/data/input/'
if not os.path.exists(dirs):
os.makedirs(dirs)
判断文件是否存在
import os
filename = 'D:/Project_QF/Amyloid_search/id/contact_potential.txt'
if not os.path.exists(filename):
os.system(r"touch {}".format(path))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)