os.remove() 就是刪除文件的
os.removedirs() 就是刪除文件夾的
os.path.exists() 用來判斷文件或文件夾是否存在
import os
path = "D:\\hello.py"
if(os.path.exists(path)): # 判斷文件是否存在
os.remove(path) # 刪除文件
path = "D:\\hello"
if(os.path.exists(path)): # 判斷文件夾是否存在
os.removedirs(path) # 刪除文件夾
喜歡的點個贊❤吧!