加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vb.net 判断文件夹存在并创建文件夹(亲自实践)

发布时间:2020-12-17 08:07:08 所属栏目:百科 来源:网络整理
导读:有时候我们需要判断某个指定的文件夹是否存在,如果不存在则提示用户是否创建 程序如下: 判断指定文件夹是否存在(保存在common文件中,方便其他程序调取) ' "文件夹存在CHECK" Public Function isDirExist(ByVal strPath As String) As Boolean Dim strDi

有时候我们需要判断某个指定的文件夹是否存在,如果不存在则提示用户是否创建

程序如下:

判断指定文件夹是否存在(保存在common文件中,方便其他程序调取)

    ' "文件夹存在CHECK"
    Public Function isDirExist(ByVal strPath As String) As Boolean
        Dim strDirTemp As String()
        strDirTemp = strPath.Split("")
        strPath = String.Empty
        For i As Integer = 0 To strDirTemp.Length - 1
            ' 判断数组内容.目的是防止输入的strPath内容如:c:abc123 最后一位也是""
            If strDirTemp(i) <> "" Then
                strPath += strDirTemp(i) & ""
            End If
        Next

        ' 判断文件夹是否存在
        isDirExist = System.IO.Directory.Exists(strPath)
    End Function


画面程序调用:

        '  检查设定的输出报表路径是否存在
        If common.isDirExist(Me.txtOutputPath.Text.Trim()) = False Then
            ' 设定的输出报表路径不存在的场合,确认是否要创建该路径
            If MsgBox("设定的输出报表路径: " & Me.txtOutputPath.Text.Trim() & " 不存在,是否创建该路径?",MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                ' 创建设定的文件夹
                My.Computer.FileSystem.CreateDirectory(Me.txtOutputPath.Text.Trim())
                Return True
            Else
                Me.txtOutputPath.Focus()
                Return False
            End If
        End If

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读