Solved

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

Posted on 2003-11-13
11
305 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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
 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

770 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