Python实现查找指定文件夹内指定时间之后修改过的文件

作者在 2010-06-09 13:24:40 发布以下内容

保存下来,以后说不定用的到

#!/usr/bin/python
#
-*- coding: UTF-8 -*-

import os
import time
import datetime

time1 = '2010-4-1 12:33'   #指定时间
root1 = 'D:\\WWW'          #指定文件夹

def txt_2_time(txt):
    l = txt.replace(' ','-').replace(':','-').split('-')
    l = map(int,l)
    s = datetime.datetime(*l)
    t = time.mktime(s.timetuple())
    return t


for root,dirs,files in os.walk(root1):
    for file in files:
        f = os.path.join(root,file)
        mtime = os.path.getmtime(f)
        if os.path.splitext(f)[1] in ('.html','.php') and mtime > txt_2_time(time1):
            print f,time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(mtime))
Python | 阅读 5773 次
文章评论,共0条
游客请输入验证码
浏览2793122次
文章归档