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

来源:互联网 发布:小黄鸭淘客软件合法吗 编辑:程序博客网 时间:2024/05/18 17:05
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

0 0
原创粉丝点击