2020年9月2日 星期三

vb.net 檢查無效路徑 [Check Path is available]

1
2
3
    Private Function NameCheck(ByVal strName As String) As String
        Return String.Join("_", strName.Split(IO.Path.GetInvalidFileNameChars))
    End Function





 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
    Private Function PathCheck(ByVal strPath As String) As String
        Dim strSplit() As String = Split(strPath, ":")
        Dim strNewPath As String = strSplit(0)
        If strSplit(0).Length > 1 Then
            strNewPath = strNewPath.Substring(0, 1)
        End If

        strNewPath &= ":"

        Dim strSplitF() As String = Split(strSplit(1), "\")

        For Each Str As String In strSplitF
            If Str <> "" Then
                strNewPath &= "\" & NameCheck(Str)
            End If
        Next

        Return strNewPath
    End Function

沒有留言:

張貼留言