- 论坛徽章:
- 4
|
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)
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/39578/showart_1004457.html
[ 本帖最后由 lvxinzhi 于 2008-6-21 05:29 编辑 ] |
|