I generate an array from the folders in a directory; which is placed in an array. i then compare it for changes in the currant folder.This way i can monitor for new files that are add to the system and trigger the script.

but i am having problems comparing the array against the currant files. my code looks like this.

import time
import os

path_to_watch = []
path_to_watch.append("/folder1/")
path_to_watch.append("/folder2/")
path_to_watch.append("/folder3/")

before =[[] for i in range(len(path_to_watch))]
for item, folder in enumerate(path_to_watch):
    before[item].append([f for f in os.listdir (folder)])
print before
while 1:
  time.sleep (3)
  for item, folder in enumerate(path_to_watch):
      after = [f for f in os.listdir (folder)]
      added = [f for f in after if not f in before[item]]
      removed = [f for f in before[item] if not f in after]
      if added:
            print "Images Added: ", ", ".join (added)
      if removed:
            print "Images Removed: ", ", ".join (removed)
      before[item] = after

Did you check my code snippet for same thing. I keep only set of all full path file names and of course the directories, you could just add all subdirs to path list to keep eye on.
Watch for change of files in directories

no i missed that- thanks very much thats solves it i believe!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.