Solved

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

Posted on 2003-11-13
11
303 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
11 Comments
 
LVL 85

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
 
LVL 11

Accepted Solution

by:
bingie earned 43 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 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 41 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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 41 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now