[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 153
  • Last Modified:

2 Apps access the same directory.

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
akarapol
Asked:
akarapol
1 Solution
 
akarapolAuthor Commented:
Edited text of question
0
 
swiltCommented:
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
 
watyCommented:
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now