Directory Watcher

You can use this script, if you want to watch for activity on a
directory. It shows you every write and delete of a file in a specified
directory.

import os, time
path_to_watch = "c:\temp"
before = dict ([(f, None) for f in os.listdir (path_to_watch)]) 
while 1: 
  time.sleep (10) 
  after = dict ([(f, None) for f in os.listdir (path_to_watch)]) 
  added = [f for f in after if not f in before] 
  removed = [f for f in before if not f in after] 
  if added: print "Added: ", ", .join (added) 
  if removed: print "Removed: ", ", ".join (removed) 
  before = after

Leave a Reply

Your email address will not be published. Required fields are marked *