I'm beginner in Python and I'm wondering to know how can I add a condition in this code to read only all new files of .../data/ directory (for example from 24 hours ago) or (from last execution time). Because I parse my .xml files every day and it is parsing all old files again and it takes time.
from lxml import etree as ET
import glob
import sys
import os
path = '/home/sky/data/'
for filename in glob.glob(os.path.join(path, '*.xml')):
try:
tree = ET.parse(filename)
root = tree.getroot()
#other codes here
except Exception:
pass
Thanks!
解决方案for filename in glob.glob(os.path.join(path, '*.xml')):
if os.path.getmtime(filename) < time.time() - 24 * 60 * 60: # 24h ago
continue # skip the old file
...