Monday, June 11, 2012

WLST script to monitor for the presence of files in a directory

It will poll every second a directory, and write to a log file the name of all the files it can find...

Very useful to monitor the behaviour of a File Adapter...

#Checks at regular intervals for the presence of a file in a Directory
import os
import datetime
import time

dirToWatch = '/data/my/directory' 
while 1 == 1 :
     files = os.listdir(dirToWatch)
     if len(files) > 0:
        logfile = open("fileslog.log", "a")
        logfile.write(str(datetime.datetime.now()) + " " + str(files) + "\n")
        logfile.close()
        time.sleep(1)



No comments: