楼上的程序有BUG,我修订了一下,在win2003,py2.5下通过,如下:
- #create by chenhuajie 2007-11-24
- 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[i])[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[i])
- log=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+" remove "+path+filelist[i]+" success \n"
- except:
- log=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+" remove "+path+filelist[i]+" fail \n"
- fTemp=open(path2+"remove_file.log", 'a')
- fTemp.write(log)
复制代码[
本帖最后由 hawkli 于 2009-2-5 20:13 编辑 ]
我的SHELL学习博客 http://hawkli.bokee.com/
我的python博客 http://hawkli.cublog.cn/
IOMS集中运维管理系统 http://code.google.com/p/ioms/
python开发的网络音乐电台 http://kange.me/
地址:http://bbs.chinaunix.net/thread-1003310-1-1.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。