Link to home
Start Free TrialLog in
Avatar of turnerrob
turnerrob

asked on

Opening a File to Read (Allready Open By Another Program)

I am reading files from a directory , the files in this directory are being generated by another program (not written by me), I do not know what language it is written in. (but the program is pretty old)
This other program refreshes the same file name with new data, approx every 20 seconds.
The problem i am having is.. My vb program opens the file for input, reads the data and then closes. If i am in the middle of reading the file and the other program tries to rewrite the file, the other program bombs out with a system error.
Have tried.. renaming,copying etc (everything!!)  .. the file i need, but still strike the problem.
Am thinking i will have to look at the time of the file and calculate the safest time to read the file????

Is there any other way of overcoming the problem., other than the above idea

Appreciate any ideas!!!
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

What function are you using to copy the file with?  You could try using the FileCopy API.

http://www.mentalis.org/apilist/CopyFile.shtml

Idle_Mind
Avatar of bingie
bingie

You mentioned copying, but did you copy the file to a new location and then read from the copy? You can copy the file, read the data and close the file, the other program shouldn't bomb this way.
Avatar of turnerrob

ASKER

I have tried using filecopy , and copy to another directory etc.
If i use filecopy and the other program tries to write over the top, it bombs out.
ASKER CERTIFIED SOLUTION
Avatar of bingie
bingie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think this is the case, ie the old program is opening (exclusive)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
_agj_
I agree this is my only option.
I only put the question, in case, there was some magic method of overcoming reading an (exclusive open) file.
Looks like there is none????
hey, if there were a way to read an exclusively open file, then wudnt it cease to be 'exclusive' :D
appreciate the help offered.
sorry i left the question open for so long