python 查找最近修改的文件

#!/usr/bin/python #-*- coding:utf-8 -*-  import os import time import datetime class Helper(): def __init__(self, duration): self._duration = duration self._logFile = open(os.path.join(r"E:\study\vstest\workHelper", datetime.datetime.now().strftime("%Y%m%d%H") + ".txt"), 'w') self._now = datetime.datetime.now() self._fileType = ['js','cs','aspx','css','png','jpg','gif',] def findFiles(self, path): for ff in os.listdir(path):
            cPath = os.path.join(path, ff) if os.path.isfile(cPath): self._handleFile(cPath) elif os.path.isdir(cPath): self.findFiles(cPath) def _handleFile(self, file): if file.split('.')[-1].lower() in self._fileType:
            filemt = time.localtime(os.stat(file).st_mtime)
            filetime = datetime.datetime(filemt[0], filemt[1], filemt[2], filemt[3]) if (self._now-filetime).days <= self._duration: self._logFile.writelines(file[ file.index("\\Gantt\\") + 13:] + "\n") def handleCode(self, str): return str.decode('utf-8').encode('gbk') if __name__ == "__main__":
    helper = Helper(0)
    helper.findFiles(helper.handleCode(r"E:\work\项目\Gantt"))

你可能感兴趣的:(python 查找最近修改的文件)