Helpful Information
 
 
Category: Visual Basic Programming
how to know whether a file is completely written

Ok..,

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.

thanks

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.

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.

how do i check if the process is still running
?

You need to get the window's handle.

Here is a code example for several shell functions.
http://www.freevbcode.com/ShowCode.Asp?ID=1308

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.

Ray

Thanks for the help guys










privacy (GDPR)