How to know if a file is ready.

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?
 
D

Del

Just check for IO errors. If there are any then the files are most probably
in use

Crouchie1998
BA (HONS) MCP MCSE
 
M

Manuel

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top