Python通过win32api递归遍历目录删除指定文件的代码

如下的内容是关于Python通过win32api递归遍历目录删除指定文件的内容。

成都创新互联公司自2013年起,是专业互联网技术服务公司,拥有项目成都网站建设、成都做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元静宁做网站,已为上家服务,为静宁各地企业和个人服务,联系电话:18980820575

import win32con
import win32api
import os

def del_dir(self,path):
    for file in os.listdir(path):
        file_or_dir = os.path.join(path,file)
        if os.path.isdir(file_or_dir) and not os.path.islink(file_or_dir):
            del_dir(file_or_dir) #it's a directory reucursive call to function again
        else:
            try:
                os.remove(file_or_dir) #it's a file, delete it
            except:
                #probably failed because it is not a normal file
                win32api.SetFileAttributes(file_or_dir, win32con.FILE_ATTRIBUTE_NORMAL)
                os.remove(file_or_dir) #it's a file, delete it
        os.rmdir(path) #delete the directory here

网站题目:Python通过win32api递归遍历目录删除指定文件的代码
转载来源:http://bzwzjz.com/article/pdjegi.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 成都网站建设 成都营销网站建设 定制网站建设多少钱 成都网站制作 宜宾网站设计 重庆网站制作 企业网站建设 响应式网站设计 成都网站建设公司 成都网站建设公司 重庆网站建设 四川成都网站建设 手机网站建设套餐 成都定制网站建设 成都网站设计公司 成都商城网站建设 成都网站建设公司 泸州网站建设 重庆企业网站建设 成都网站设计 app网站建设 高端网站设计