For combining (1) and (2) you can reverse the sort by only trying if your are under a test directory
Also this is a great use for a generator / map combo to avoid extra loops
import os
import re
is_xml = re.compile('xml', re.I)
is_test = re.compile('testResults', re.I)
def find_xml_tests(root):
for current, dirnames, filenames in os.walk(root):
if is_test.search(current):
for filename in filenames:
filter(lambda ifp: is_xml.search(filenamep):
, filenames):
yield os.path.normpath(os.path.join(current, filename))
def touch(filename ):
os.utime(test,(time.time(),time.time()))
map(touch, find_xml_tests('path/to/files'))