如果文件夾不存在就創(chuàng)建断部,如果文件存在就清空呢燥!
import os
import shutil
def setDir(filepath):
'''
如果文件夾不存在就創(chuàng)建,如果文件存在就清空原茅!
:param filepath:需要創(chuàng)建的文件夾路徑
:return:
'''
if not os.path.exists(filepath):
os.mkdir(filepath)
else:
shutil.rmtree(filepath)
os.mkdir(filepath)