Watch for change of files in directories

TrustyTony

This problem came up in one thread and here is my finalised version to follow changes of files in list of paths given.

552 Views
About the Author

IT Pro doing Eng-Fin-Eng translations

import os,time
path_list=['/Python Projects','/Python26',
           '/Python26/Lib','/Python26/Lib/site-packages']
path_list=[os.path.realpath(p) for p in path_list]

def files(path_list):
    fileset=set()
    for path_to_watch in path_list:
        for f in os.listdir(path_to_watch):
            fileset.add(os.path.join(path_to_watch,f))
    return fileset
    
while 'Allways':
    before=files(path_list)
    time.sleep (3)
    after=files(path_list)
    if after != before:
        added = ",".join(after-before)
        removed = ",".join(before-after)
        print 'Added: %s\nRemoved: %s\n' % (added,removed)