1. 程式人生 > >VB.net檢查檔案是否正在被使用的函式

VB.net檢查檔案是否正在被使用的函式

Public Function IsFileReady(ByVal filepath As String) As Boolean '檢查檔案是否正在被使用的函式
If File.Exists(filepath) = False Then
Return True
Exit Function '如果filpath檔案不存在,也就不沒有被佔用,應該返回true
End If
Try
File.Open(filepath, FileMode.Open).Close()
Return True
Catch e As Exception
'MsgBox("Writing was disallowed, as expected: " & e.ToString())
Return False
End Try


End Function