Solved

2 Apps access the same directory.

Posted on 1998-09-22
3
143 Views
Last Modified: 2010-04-30
I am writing 2 separate programs that need to access the same directory. The first application will save the files in the directory. The second application will have to copy all the files in the same directory to the remote machine and delete it. The problem is there is a chance that the first application is still trying to write a file and the second  application have reading the partial of it to the remote machine. What is the best method to accomplish this?

My current idat is to have a status file. I think maybe I can have a dummy file with 0 byte to indicate which application is using the directory. If the first application lock this file then the second app will wait until this file is unlock. When the second app gain control by locking the dummy file, the first application will wait. However I don't know how to  lock the file or how to check if the file is currently locked or not. Please suggest me on this and also if you have any better idea.
0
Comment
Question by:akarapol
3 Comments
 

Author Comment

by:akarapol
ID: 1436167
Edited text of question
0
 
LVL 2

Accepted Solution

by:
swilt earned 50 total points
ID: 1436168
Public Function bIsFileReallyThere(ByVal sFile As String) As Boolean
    On Error GoTo EHbIsFileReallyThere
   
    Dim bRet As Boolean
    Dim fh As Integer
   
    bRet = True
    fh = FreeFile
    Open sFile For Input As #fh
    Close #fh
    bIsFileReallyThere = bRet
    Exit Function
   
EHbIsFileReallyThere:
    bRet = False
    Resume Next
End Function
0
 
LVL 14

Expert Comment

by:waty
ID: 1436169
akarapol,

We do exactly the same thing here. here is the process :

We have an application wich creates files like b******.sp
Once the file is completely written on disk, the application write a file like c******.sp (****** is the same for both files)
We have another app wich looks in the directory for files begining by "c". Once the application find a file, it knows that a "b" files is there, and do is process.

If you want, I can post you code here.
0

Featured Post

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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.
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…

809 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