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

猜你喜欢

转载自blog.csdn.net/polloo2012/article/details/82183031