当前位置: 移动技术网 > IT编程>脚本编程>Python > python遍历文件夹并删除特定格式文件的示例

python遍历文件夹并删除特定格式文件的示例

2019年04月01日  | 移动技术网IT编程  | 我要评论

化妆品加工,朴灿烈我们结婚了,真心英雄串词

复制代码 代码如下:

#!/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)

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网