wait-for creation of file

jke

New Member
Hello,

I am currently writing an application that has wait until a file exist, if it exist, handle the contents and delete it and again wait until it is recreated by another process.

The only sollution I have found so far is the following:

Code:
do while lContinue:
  file-info:file-name = cFilename.
  if file-info:full-pathname <> ? then
      run process-file.
end.
The problem with this sollution is that it uses a lot of processor time. An obvious sollution would be to put pause 1. in the loop, but this causes unwanted delays.

Is there a simple way to solve this?

Thanks,

Jan
 
If this is running in windows, you may want to use PSTimer to periodically check the directory of files. Save alot on processor usage. There is a sample application in %DLC%\src\samples\ActiveX.

If this running on a Unix based system, you can also setup a cron job to run every 1 min and execute a progress batch job to read the directory.
 
delays are to be avoided

The session itself is running in DOS (yes I know ;-)). Delays should be avoided as much as possible.
 
On Unix I would go for directory spooler. Dunno if something like that exists in DOS?
Just generate a file, if it's generated,then move it to the directory where the directory spooler points and then process the file.

Casper.
 
One detail I didn't mention is that I also control the process that produces the files. So I've solved the problem in another way: I've made a sonic queue on which the dos process is listening, I put a message on that que when the file is created so it can be handled. This way I can wait without spoiling resources (in the infinite while true loop), although I feel this is a bit overkill it does work beautifully.

Now for the directory spooler. I also use unix (and at home, only linux), but I've never heard of a directory spooler. What exactly is that?
 
Sorry,

What I meant is that you can write a shellscript which periodically looks into a directory and as soon as a file is there it runs another script or a progress .p or takes some other action. We have such mechanism and we call it directory spooler. I'm so used to it that I wrote it like it's standard UNIX functionality which it isn't.
But in essence the same result as using Sonic and let the program listen to a queue.

Casper.
 
Back
Top