Solved

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

Posted on 2003-11-13
11
307 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
11 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
Industry Leaders: 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 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 86

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
 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

710 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