#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    10
    Rep Power
    0

    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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    138
    Rep Power
    12
    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.
    --

    ngibsonau
  4. #3
  5. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    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.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    10
    Rep Power
    0

    how


    how do i check if the process is still running
    ?
  8. #5
  9. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    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
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    NJ, USA
    Posts
    11
    Rep Power
    0
    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
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    10
    Rep Power
    0

    sweet


    Thanks for the help guys

IMN logo majestic logo threadwatch logo seochat tools logo