Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2003-11-13
11
Medium Priority
?
311 Views
Last Modified: 2010-05-18
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!!!
0
Comment
Question by:turnerrob
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 9743107
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
0
 
LVL 11

Expert Comment

by:bingie
ID: 9743119
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.
0
 

Author Comment

by:turnerrob
ID: 9743146
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Accepted Solution

by:
bingie earned 129 total points
ID: 9743158
Copy the file:

  FileCopy strSource, strDest

      e.g.

  FileCopy "C:\temp\test.txt", "C:\test\test.txt"


2.  Then read from the file as you need

3.  Then delete the file
 
  Kill "strPath"

         
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 123 total points
ID: 9743168
It is very possible that the old program is attempting to open the file in an exclusive mode which is causing it to crash.

(Thinking)...
0
 

Author Comment

by:turnerrob
ID: 9743181
I think this is the case, ie the old program is opening (exclusive)
0
 
LVL 7

Assisted Solution

by:_agj_
_agj_ earned 123 total points
ID: 9745299
hey...u cud find the filetime and check up how long it takes for the next update of the file. Using the data, u cud ezly get the safe time to
copy off.
0
 

Author Comment

by:turnerrob
ID: 9750554
_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????
0
 
LVL 7

Expert Comment

by:_agj_
ID: 9761483
hey, if there were a way to read an exclusively open file, then wudnt it cease to be 'exclusive' :D
0
 

Author Comment

by:turnerrob
ID: 10168138
appreciate the help offered.
sorry i left the question open for so long
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question