#coding=utf-8
import os
import time
import datetime
def deleteOutdateFiles(path):
"""
删除目录下七天前创建的文件
"""
current_time = time.strftime("%Y-%m-%d", time.localtime(time.time()))
current_timeList = current_time.split("-")
current_time_day = datetime.datetime(int(current_timeList[0]), int(current_timeList[1]), int(current_timeList[2])) for root, dirs, files in os.walk(path):
for item in files:
file_path = os.path.join(root, item)
create_time = time.strftime("%Y-%m-%d", time.localtime((os.stat(file_path)).st_mtime))
create_timeList = create_time.split("-")
create_time_day = datetime.datetime(int(create_timeList[0]), int(create_timeList[1]), int(create_timeList[2]))
time_difference = (current_time_day - create_time_day).days
if time_difference > 7:
os.remove(file_path)

python删除目录下七天前创建的文件的更多相关文章

  1. Windows 定时删除指定路径下N天前的日志文件

    Windows 定时删除指定路径下N天前的日志文件 Windows 下bat脚本文件的内容为 1. 删除指定路径下5天前的所有文件 @echo off set SrcDir=E:\WORK\Git s ...

  2. 在自定义目录下,按日期创建excel文件

    在指定文件目录下,新建以当前日期命名的excel 文件,如果文件已经存在,在文件中新建一个sheet页来存放数据 import datetime import xlrd, xlwt import re ...

  3. 使用shell删除目录下几天前生成文件方法

    find /dbfdumpdir/*full* -mtime +21 -exec rm -rf {} \; 这个shell可以删除目录/dbfdumpdir下面21天前生成的,文件名包含full的文件 ...

  4. PHP删除目录下包含某个字符串的全部文件

    //获取全部的路径 function tree(&$arr_file, $directory, $dir_name='') { $mydir = dir($directory);    whi ...

  5. Linux下如何遍历指定目录下的所有文件并删除指定天数之前创建的文件

    脚本内容如下: #!/bin/bash function delete_file { days=$[$-] for i in `find $dir -type f -ctime +$days` do ...

  6. 模拟主库创建数据文件,dg备库空间不足时问题处理

    本篇文档测试目的: 模拟实际环境中,主库对表空间添加数据文件,备库空间不足,最终导致MRP进程自动断开,处理方式. 1.问题环境模拟 1)正常情况下的dg 主库创建数据文件,备库接受日志,自动创建表空 ...

  7. window 上创建 .gitignore文件

    由于 git默认不上传空文件夹,如果需要上传空文件夹,那么需要这样上传空文件,官方给出这样的做法~~ (需要创建.gitignore文件) 在linux 上比较好操作了,这里说下在window 上 创 ...

  8. python(6)时间戳和北京时间互转,输出当前的时间和推到七天前的日期

    项目发展的需要:(包含时间函数)time datetime 时间戳和北京时间互转 import time import datetime s = '2015-04-17 11:25:30' d = d ...

  9. python(七) Python中单下划线和双下划线

    Python中单下划线和双下划线: 一.分类 (1).以单下划线开头,表示这是一个保护成员,只有类对象和子类对象自己能访问到这些变量. 以单下划线开头的变量和函数被默认是内部函数,使用from mod ...

随机推荐

  1. ID4收藏

    IdentityServer4.Admin https://github.com/skoruba/IdentityServer4.Admin

  2. centos 6.5 安装mysql 5.7.21 community

    Step1: 检测系统是否自带安装mysql # yum list installed | grep mysql Step2: 删除系统自带的mysql及其依赖命令: # yum -y remove ...

  3. 1年3年5年-我对PHP攻城师有看法

    今天早上公车上看微信拉勾的一些岗位推送,挑了几个PHP攻城师看看 15K-20K的 百万级网站架构经验 3年以上开发,至少1年互联网用户产品开团队开发经验 不低于百度T4水平 数据库规划和优化,熟悉常 ...

  4. Prerender Application Level Middleware - ASP.NET Core Middleware

    In the previous post Use Prerender to improve AngularJS SEO, I have explained different solutions at ...

  5. Tuning 05 Sizing other SGA Structure

    Redo Log Buffer Content The Oracle server processes copy redo entries from the user’s memory space t ...

  6. 第二百三十三节,Bootstrap表格和按钮

    Bootstrap表格和按钮 学习要点: 1.表格 2.按钮 本节课我们主要学习一下 Bootstrap 表格和按钮功能,通过内置的 CSS 定义,显示各 种丰富的效果. 一.表格 Bootstrap ...

  7. centos7 禁用每次sudo 需要输入密码

    安装完centos7后,默认没有启用sudo,首先应该是对sudo进行设置.sudo的作用就是使当前非root用户在使用没有权限的命令 时,直接在命令前加入sudo,在输入自己当前用户的密码就可以完成 ...

  8. ChemDraw进行自动调整的步骤

    说到化学绘图软件那就不得不提ChemDraw,起非常的经典在国内外都得到了普遍应用,最新版是ChemDraw 15.1 Pro.在使用ChemDraw化学绘图工具绘制化学图形的时候,需要循序渐进一步一 ...

  9. CSV转PDF(C++)

    CSV : Comma Separate Values 特点: 每条记录占一行 以逗号为分隔符 逗号前后的空格会被忽略 字段中包含有逗号,该字段必须用双引号括起来 字段中包含有换行符,该字段必须用双引 ...

  10. Django model :add a non-nullable field 'SKU' to product without a default; we can't do that

    You are trying to add a non-nullable field 'SKU' to product without a default; we can't do that (the ...