您的位置:首页 > 编程语言 > VB

VB.NET 判断文件夹目录与文件是否存在检查

2012-05-27 20:23 771 查看
Private Sub BTN_LOAD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesBTN_LOAD.Click

'文件夹
CHECK

If Not blnDirExist(TXT_PATH.Text.Trim) Then

MsgBox("文件夹路径不存在")

BTN_LOAD.Focus()

Exit Sub

End If

'文件
CHECK

If Not blnFileExist(TXT_PATH.Text.Trim) Then

MsgBox("文件不存在")

BTN_LOAD.Focus()

Exit Sub

End If

End Sub

#Region "文件夹存在CHECK"

Private Function blnDirExist
(ByVal strPath As String) As Boolean

Dim strDirTemp As String()

strDirTemp
= strPath.Split("\")

strPath = String.Empty

For i As Integer =
0 To strDirTemp.Length – 2

strPath
+= strDirTemp(i) & "\"

Next

blnDirExist = System.IO.Directory.Exists(strPath)

End Function

#End Region

#Region "文件存在CHECK"

Private Function blnFileExist
(ByVal strFile As String) As Boolean

blnFileExist = System.IO.File.Exists(strFile)

End Function

#End Region
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: