您的位置:首页 > 编程语言 > Python开发

python 实现递归删除文件和文件夹

2016-12-29 13:11 686 查看
def removeDir(dirPath):
if not isdir(dirPath):
return
files = listdir(dirPath)
try:
for f in files:
filePath = join(dirPath, f)
if isfile(filePath):
remove(filePath)
elif isdir(filePath):
removeDir(filePath)
rmdir(dirPath)
except Exception, e:
print e
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: