February 5th, 2003, 04:57 PM
how to know whether a file is completely written
I am making a shell() call to a progam X that takes an input file and creates an output file. I want to delete the input file after the output file is created and the program is done running. I have tried sloppy solutions like waiting but it just doesn't work consistantly.
so sudo code would be:
shell(C:\X /I input_file /O output_file);
delete input file
will sometimes produce error input file is in use.
So my question would be, how can I know that the output file has been completely written so that I may delete the input file.
February 11th, 2003, 06:53 AM
why not make x create another file after its finished say output_file.fin
you can then poll for the existence in a loop.
You could even put the loop to sleep somehow in between to make it more CPU friendly.
February 11th, 2003, 09:29 AM
There are two other possible solutions here.
1) check for the existence of the program that is generating the file. If it is still running, then it isn't done yet.
2) use vb to create the file instead of doing it with an external program, then you know when it is done.
February 11th, 2003, 01:01 PM
how do i check if the process is still running
February 11th, 2003, 01:32 PM
February 25th, 2003, 04:36 PM
With a timer control in vb, you can also try to open the file for write, exclusive and wait until it does not fail. Make sure that you have a timeout for, should the shell program fail you VB program will hang.
Use the timer so the vb program does not go crazy looping waiting for the file to close and sucking life out of the CPU . Make sure to use doevents too.
February 27th, 2003, 02:32 PM