python遍历当前目录并删除某文件
2024-09-06 04:02:22
#coding: utf-8
"""
this programe is to clear driverlog below this dir
__author__:the_new_one
"""
import os, traceback #查找文件名中包含关键词的文件
def search_dir(s, path=os.path.abspath('.'),files = []):
try:
for x in os.listdir(path):
path_now = os.path.join(path, x)
if os.path.isfile(path_now) and s in os.path.splitext(x)[0]:
print path_now
#删除查找到的文件
os.remove(path_now)
if x not in files:
files.append(x)
elif os.path.isdir(x):
search_dir(s=s, path=os.path.join(path_now), files=files)
return files
except Exception, e:
print traceback.format_exc()
print e if __name__ == "__main__":
result = search_dir(s='xxx')
通过遍历当前路径下的文件,判断文件名是否包含s,如果是就删除。
最新文章
- app的meta标签
- request 路径随笔
- Mysql分支
- 实例源码--Android手机狗(防盗)源码
- 九度OJ 1118 数制转换
- mac 布置 git仓库服务器
- 读书笔记之 - javascript 设计模式 - 责任链模式
- delphi列表视图组件(TListView)使用方法|实例
- Codecademy学习打卡1
- Swift - 多线程实现方式(3) - Grand Central Dispatch(GCD)
- Java中WebService实例
- Jquery源码分析与简单模拟实现
- Linux网络技术管理及进程管理
- RestSharp发送请求得到Json数据
- 第五篇:数据备份、pymysql模块
- react框架实现点击事件计数小案例
- python标准库 - 数学库和随机数库
- 【python基础】利用pandas处理Excel数据
- Dell服务器Raid5之后安装系统
- linux下面得小数计算
热门文章
- Python学习-day15-JavaScript
- [oldboy-django][2深入django]xss攻击 + csrf
- Zookeeper CreateMode
- linux配置Hadoop伪分布安装模式
- File IO(NIO.2):什么是路径?
- 【bzoj4810】[Ynoi2017]由乃的玉米田 莫队算法+STL-bitset
- Codeforces Round #330 (Div. 2) B 容斥原理
- react-router 4.0版本学习笔记
- 带接口的webservice 的发布
- boost 库的下载和编译_Visual Studio 2013(转)