我是靠谱客的博主 冷傲发夹,这篇文章主要介绍python 删除目录_python删除整个目录(目录非空),现在分享给大家,希望可以做个参考。

python删除整个目录(目录非空),os.rmdir()只能删除空目录,下面的函数可以删除整个非空目录

import os

import shutil

def CleanDir( Dir ):

if os.path.isdir( Dir ):

paths = os.listdir( Dir )

for path in paths:

filePath = os.path.join( Dir, path )

if os.path.isfile( filePath ):

try:

os.remove( filePath )

except os.error:

autoRun.exception( "remove %s error." %filePath )#引入logging

elif os.path.isdir( filePath ):

if filePath[-4:].lower() == ".svn".lower():

continue

shutil.rmtree(filePath,True)

return True

Dir = "D:\Temp"

CleanDir(Dir)

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com

特别注意:本站所有转载文章言论不代表本站观点!

本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

最后

以上就是冷傲发夹最近收集整理的关于python 删除目录_python删除整个目录(目录非空)的全部内容,更多相关python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(62)

评论列表共有 0 条评论

立即
投稿
返回
顶部