Finding windows OS files modified in time range with python

We had a need to search some text files in Windows modified during a certain time range with a given piece of text. This is a network drive that is not indexed, so we couldn’t quickly rely on a windows search.

We came up with what is below…

import os
from time import localtime
files = os.listdir('w:/nascar/pimfeed/ean/')
for f in files:
  p = localtime(os.path.getmtime('w:/nascar/pimfeed/ean/' + f)) 
  #find files modified since April 2014, inclusive
  if p[0] == 2014 and (p[1] >= 4):
    print "processing",f, "modified on",p[0],"/",p[1],"/",p[2]
    for line in open('w:/nascar/pimfeed/ean/' + f,"r"):
      if line.find("1187574362005036") > -1:
        print f,"has it!"

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.