我是靠谱客的博主 执着美女,这篇文章主要介绍python删除非空目录的方法,现在分享给大家,希望可以做个参考。

#!/usr/bin/env python
#-*- coding: utf-8 -*-

import win32con, win32api,shutil,os

def removePath(destinationPath):
'''
@summary: 删掉destinationPath目录,当然包括其中的子目录和文件
@param destinationPath: 所给目标目录
'''
if os.path.exists(destinationPath):
pathList = os.listdir(destinationPath)
for path in pathList:
pathFull = os.path.join(destinationPath,path)
if os.path.isfile(pathFull):
win32api.SetFileAttributes(pathFull, win32con.FILE_ATTRIBUTE_NORMAL)
if os.path.isdir(pathFull):
removePath(pathFull)

shutil.rmtree(destinationPath,True)

if __name__ == '__main__':
path = r'e:testtest'
removePath(path)

最后

以上就是执着美女最近收集整理的关于python删除非空目录的方法的全部内容,更多相关python删除非空目录内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部