Solved

2 Apps access the same directory.

Posted on 1998-09-22
3
141 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 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

20 Experts available now in Live!

Get 1:1 Help Now