Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2291126
  • 博文数量: 321
  • 博客积分: 3440
  • 博客等级: 中校
  • 技术积分: 2992
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-24 09:08
个人简介

我就在这里

文章分类

全部博文(321)

文章存档

2015年(9)

2014年(84)

2013年(101)

2012年(25)

2011年(29)

2010年(21)

2009年(6)

2008年(23)

2007年(23)

分类: Python/Ruby

2008-06-18 11:19:32

import os, sys,datetime,time
from stat  import *

path='c:\\test\\'
path2='c:\\test\\'
filelist=[]
filelist=os.listdir(path)
for i in range(len(filelist)):
        t1 = time.gmtime(os.stat(path+filelist)[ST_MTIME])  #get file's mofidy time
        t11 =  time.strftime('%Y-%m-%d',t1)
        year,month,day=t11.split('-')
        t111= datetime.datetime(int(year),int(month),int(day))       
        t2 = time.gmtime()
        t22 =  time.strftime('%Y-%m-%d',t2)
        year,month,day=t22.split('-')
        t222= datetime.datetime(int(year),int(month),int(day))       
        days =  (t222-t111).days
        if days>5 :  # if over 5 days then remove file
                try:
                        os.remove(path+filelist)
                        log=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+"  remove "+path+filelist+"  success \n"
                except:
                        log=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+"  remove "+path+filelist+"  fail \n"               
                fTemp=open(path2+"remove_file.log", 'a')       
                fTemp.write(log)
阅读(2003) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~