How Can I Easily Determine If A File Has been Added to a Directory

I am uploading files that need to be processed prior to uploading. I will put the files in a directory. My question is how can I write an easy process to kick off a script once a file has been added? Is there an easy way to determine if a file has been added to a directory?

Thanks

At the end of you script create a file in the same directory with a name you like.

At the start of your script search for files which are newer than the file you created in your previous run.

script:
-------------------------------------------------------------------
#!/usr/bin/ksh

cd /somedir
for FILE in `find ./* -prune -type f -newer ./TIMEFILE`
do
# do whatever you wanna do with the new files.
done

touch ./TIMEFILE
-------------------------------------------------------------------

if you want to include subdirectories as well replace
find ./* -prune -type f -newer ./TIMEFILE
by
find . -type f -newer ./TIMEFILE

The touch command makes sure the file TIMEFILE always has a timestamp of when the last run of your script ended.

The find command will find only find files which have been place in the directory of the timestamp time of TIMEFILE

Thanks SB008,

I need to know in Real Time. I should have mentioned that.

Thanks again for the reply

Instead of
touch ./TIMEFILE
you use
date > ./TIMEFILE

At the beginning of the script something like:
OLDDATE=`cat ./TIMEFILE`

Would I need a loop to check the directory to verify when the file was added?

Since you are doing the upload, simply invoke the script as you finish the upload.

I was told to run a cron job every 2 minutes and once it found the file I could have it transfer it. It seems like overkill to have a process running every 2 minutes looking for a file that may be added only once a day.

Thanks to all who answered

you asked the same question in a different thread?

I am assuming this is the same thing you wanted to check every 2 minutes? I posted the code for that in your other thread.