Link to home
Start Free TrialLog in
Avatar of edfreels
edfreelsFlag for United States of America

asked on

how to determine if file transfer is complete with vb6

I have a program that is looking in a specific folder for incoming zip files.  These files are coming through a 56k pipe on our network so it usually takes approximately 1-2 minutes for the file to be completely copied from the remote location.  I need a way to determine when the file is released(not in use/transfer complete) so I can then test to make sure it is a valid zip and then process accordingly.  If the connection breaks and the file doesn't get transferred completely, I then test to determine whether it is a valid zip or not and process accordingly.  

If I run the test before the file transfer completes, it just looks like it is a bad zip.  The problem is that sometimes there are broken transmissions and there are actually bad zips out there.  When I come across these files I move them to a "bad zip" folder.

Is there anything that writes to the file attribute or any sort of flag that signals when the file is released or the transfer is finished?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Along the same lines as angelIIIs comments....if you can control the filenames being sent to you....I once embedded each file size into its filename so I could see if it was all there or not.
Avatar of edfreels

ASKER

AngelIII,

It is not feasible to do your first suggestion but your second suggestion is intriguing. Can you explain what this line is doing?  

I am receiving a compile error "Expected: Read or Write" with the "AS" highlighted in the line of code after adding.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Guys,

Thanks for you help.  You both got me on the right track but I found a function that did exactly what I needed using API calls.  Again, you pointed me in the right direction though so I will give you both credit.  Thanks!  Just to share for future knowledge, below is a function to check if a file is open.  With this I could just do an if...then and bypass the file if it was still being transferred and go on to the next file:

' Declaration for APIs used by IsFileAlreadyOpen function...
    Private Declare Function lopen Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal iReadWrite As Long) As Long
    Private Declare Function GetLastError Lib "kernel32" () As Long
    Private Declare Function lclose Lib "kernel32" Alias "_lclose" (ByVal hFile As Long) As Long

' Our Function...
Function IsFileAlreadyOpen(Filename As String) As Boolean
   Dim hFile As Long
   Dim lastErr As Long

   ' Initialize file handle and error variable.
   hFile = -1
   lastErr = 0

   ' Open for for read and exclusive sharing.
   hFile = lopen(Filename, &H10)

   ' If we couldn't open the file, get the last error.
   If hFile = -1 Then
      lastErr = Err.LastDllError
   ' Make sure we close the file on success.
   Else
      lclose (hFile)
   End If

   ' Check for sharing violation error.
   If (hFile = -1) And (lastErr = 32) Then
      IsFileAlreadyOpen = True
   Else
      IsFileAlreadyOpen = False
   End If

End Function


This helped me determine whether the file transfer had completed.