Shell script to execute condition until an event occurs

I need a script to keep polling "receive_dir" directory till "stopfile" get written in the directory.

This has to run despite empty directory.

So far i have this but fails if receive_dir is empty with no files with "unary operator expected". Help !!

#!/usr/bin/ksh

until [ $i = stopfile ]
 do
   for i in `ls receive_dir`; do
   time=$(date +%m-%d-%Y-%H:%M:%S)
   echo $time
   echo $i;
  done
done

It's because "$i" is initially undefined. Quoting it gets around this.

#!/usr/bin/ksh

cd $receive_dir
until [ "$i" = stopfile ]
 do
   for i in *; do
     time=$(date +%m-%d-%Y-%H:%M:%S)
     echo "$time"
     echo "$i"
  done
done

for i in `ls receive_dir`; do will produce an error if no files exist, and for i in *; do resolves to * if no files exist, and it seems a bit wasteful to scan a whole directory to look for a known file, so it's probably better just to check if the file exists.

until [ -f $receive_dir/stopfile ]

(not forgetting to add a sleep to the loop)