我是靠谱客的博主 安静硬币,这篇文章主要介绍python遍历文件夹并删除特定格式文件的示例,现在分享给大家,希望可以做个参考。

复制代码 代码如下:

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

import os

def del_files(path):
    for root , dirs, files in os.walk(path):
        for name in files:
            if name.endswith(".tmp"):
                os.remove(os.path.join(root, name))
  print ("Delete File: " + os.path.join(root, name))

# test
if __name__ == "__main__":
    path = '/tmp'
    del_files(path)

最后

以上就是安静硬币最近收集整理的关于python遍历文件夹并删除特定格式文件的示例的全部内容,更多相关python遍历文件夹并删除特定格式文件内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部