Move files one at the time and wait until the previous file is handled

I'm a novice at unix and need it more and more to do my work.
I seem running into problems getting this script "attempt" to work:

I need to copy all files in a directory, which is containing 22000 files, into a directory one level up. There a tool monitors the content of the dir and processes all .aaa files if they arrive. Unfortunately, the tool is not quick and files may only be delivered at a slow pace

The files have to be copied one by one and when the previous file is not processed, the script should loop/sleep until the previously copied file is handled.

Here is what I tried

#!/bin/ksh
for file in `ls ~/tmp/d1/.aaa�
do
while [1]
do
if [! -f /~tmp/
.aaa]
then
echo "waiting"
sleep 1
else
echo "start processing file
break
fi
done
echo "Moving $file"
mv $file ~/tmp/
done

The script keeps moving files and don't wait until the previously copied file is handled and removed.
Anybody any idea what isn't correct ? I'm very gratefull for all advise !

 
The files have to be copied one by one and when the previous file is not processed, the script should loop/sleep until the previously copied file is handled.

How do you know whether the file you copied hav processed/handled ?..

In your code your just checking for the presense of the file not whether it is handled or processed.

That's very simple, a datastage map processes the file and then moves it to a archive. So if it's not there anymore, it's processed (except when bugs arise, but that's another story).