我是靠谱客的博主 忧伤电话,这篇文章主要介绍Python彻底删除文件夹及其子文件,现在分享给大家,希望可以做个参考。

#coding:utf-8
import os
import stat
import shutil
#filePath:文件夹路径
def delete_file(filePath):
    if os.path.exists(filePath):
        for fileList in os.walk(filePath):
            for name in fileList[2]:
                os.chmod(os.path.join(fileList[0],name), stat.S_IWRITE)
                os.remove(os.path.join(fileList[0],name))
        shutil.rmtree(filePath)
        return "delete ok"
    else:
        return "no filepath"
    
print os.path.exists("E:\biancheng\python\ascas")    
print delete_file("E:\biancheng\python\ascas")



最后

以上就是忧伤电话最近收集整理的关于Python彻底删除文件夹及其子文件的全部内容,更多相关Python彻底删除文件夹及其子文件内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部