How to know if a file is ready.

  • Thread starter Thread starter Manuel
  • Start date Start date
M

Manuel

My program is monitoring the files on a folder. Some of them take a while to
be transferred and some are simply locked by the user.

How do I know when a file is "done" transferring or released by the user?
 
Just check for IO errors. If there are any then the files are most probably
in use

Crouchie1998
BA (HONS) MCP MCSE
 
You mean something like this?

Private Function FileBeingUsed(ByVal sFile As String) As Boolean
Dim fInfo As New IO.FileInfo(sFile)
If fInfo.Attributes = IO.FileAttributes.ReadOnly Then
'if the file is read only then by definition isn't it ready?
Return False
End If
Dim fNum As Integer = FreeFile()
Try
FileOpen(fNum, sFile, OpenMode.Output, OpenAccess.Write,
OpenShare.Shared)
FileClose(fNum)
Return False
Catch ex As Exception
Return True
End Try
End Function

Isn't this a little "brute force"? Do you have a better method/suggestion?
 
Back
Top