watchdog looks promising, but requires py 2.6+.
pyinotify might work, but I didn't look at it in detail.
If you are going for a fast way to get it done and don't want to have to worry about installing a package, then I would just poll the modification date in a loop with a sleep
as detailed here:
- Code: Select all
import os.path, time
files = ['file1.txt', 'file2.txt', 'file3,txt']
changes = {"file1.txt":os.path.getmtime("file1.txt"),"file2.txt":os.path.getmtime("file2.txt"),"file3.txt":os.path.getmtime("file3.txt")}
while True:
for f in files:
if changes.get(f) < os.path.getmtime(f):
print "File {} has been modified".format(f)
changes[f] = os.path.getmtime(f)
else:
print "No changes, going to sleep."
time.sleep(10)