import os import shutil from pathlib import Path def delFileAndDir(delDir): if Path(delDir).exists(): delList = os.listdir(delDir) for f in delList: filePath = os.path.join(delDir,f) if os.path.isfile(filePath): os.remove(filePath) elif os.path.isdir(filePath): shutil.rmtree(filePath,True)