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!"