Home All Groups Group Topic Archive Search About

How to know if a file is ready.

Author
24 Jan 2006 2:15 PM
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?

Author
24 Jan 2006 6:19 PM
Del
Just check for IO errors. If there are any then the files are most probably
in use

Crouchie1998
BA (HONS) MCP MCSE
Author
24 Jan 2006 7:29 PM
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?

Show quoteHide quote
"Del" <crouchie1998@spamcop.net> wrote in message
news:OXrAtNRIGHA.3936@TK2MSFTNGP10.phx.gbl...
> Just check for IO errors. If there are any then the files are most
> probably in use
>
> Crouchie1998
> BA (HONS) MCP MCSE
>