python 删除三天前的日志.py
2024-09-07 07:19:11
#获取所有文件
def file():
for cur_dir, dirs, files in os.walk(r'/学习/接口自动化/BestTest/作业/logs'): # cur_dir(当前路径),dirs(目录),files(文件)中所有的
for file in files:
abs_path = os.path.join(cur_dir, file) # 获取绝对路径
if int(timestamp_to_str(abs_path.split("_")[1].split(".")[0], format='%Y-%m-%d')) < timestamp_to_str(format='%Y-%m-%d') - 60 * 60 * 24 * 3 or os.path.getsize(abs_path) == 0:
os.remove(abs_path)
else :
print("%s文件是3天内的,不需要删除"%file)
#三天前的时间
def timestamp_to_str(stringtime=None,format='%Y-%m-%d'):
#格式化时间转换为时间戳
if stringtime:
result=time.mktime(time.strptime(stringtime,format))
return int(result)
else:
result = time.time()
return int(result) file()
最新文章
- Maven详解
- phpmyadmin导入数据库大小限制修改
- Linux下因为系统编码问题造成乱码的解决办法
- java基础-继承
- mysql load data 乱码的问题
- 创建Fragment
- DataView usage combind with event and ViewModel From ERP-DEV
- Newtonsoft.Json序列化和反序列之javascriptConvert.SerializeObject,DeserializeObject,JsonWriter,JsonReader
- HDOJ 1326 Box of Bricks(简单题)
- Fix Elementary Boot Screen (plymouth) After Installing Nvidia Drivers
- 剑指offer--面试题3
- Hadoop平台基本组成
- python 文本比对
- 【java+selenium】网易云音乐刷累计听歌数
- 利用XML语法 SQL 列转行
- Reader 与 Guava MultiReader
- m4, autoconf
- OC Foundation框架—集合
- LeetCode - 566. Reshape the Matrix (C++) O(n)
- 对于yum中没有的源的解决办法-EPEL
热门文章
- Linux 中useradd命令的使用
- 使用numpy和PIL实现图像的手绘效果
- strongsan基本用法
- 【简说Python WEB】flask-mail电子邮件异步Asynchronous
- 小白学 Python 数据分析(20):pyecharts 概述
- 【Code Force】Round #589 (Div. 2) D、Complete Tripartite
- python plt 色卡
- [LeetCode] 935. Knight Dialer 骑士拨号器
- JAVA——桌球游戏(动画)
- 报错代码:svn-http status413&#39;requset entity too large