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
VB.net检查文件是否正在被使用的函数
最新推荐文章于 2024-10-20 13:15:05 发布
博客提供了一个名为IsFileReady的公共函数,用于检查文件是否正在被使用。若文件不存在则返回True;若文件存在,尝试打开文件,若能成功打开并关闭则返回True,若出现异常则返回False。
1790

被折叠的 条评论
为什么被折叠?



