一、本文核心
介紹python中文件的基本操作。
二、正文
1、文件夾的新建和刪除
if not isExists:
# 如果不存在則創建目錄
# 創建目錄操作函數
os.makedirs(self.temp_dir)
#os.remove(self.temp_dir)
print (self.temp_dir + ' create success!!')
else:
# 如果該文件夾中有文件,則刪除
shutil.rmtree(self.temp_dir)
print(self.temp_dir + ' start rebuilt ')
2、文件的刪除
# path="./temp/txt.txt"
if os.path.exists(path):
os.remove(path)