How to get the list of all directories and subdirectories in a specified path using vb.net

后端 未结 4 608
耶瑟儿~
耶瑟儿~ 2021-01-28 10:27

My directory structure is like below.

Parent directory
---Sub directory 1 ---Sub directory 2 ------Sub directory2a ------Sub directory2b ---Sub directory 3

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-28 11:05

    Dim di As New DirectoryInfo(FolderName)
    di = New DirectoryInfo(path)
    
    rgFiles = di.GetFiles("*.*", IO.SearchOption.AllDirectories)
    
    For Each fi As FileInfo In rgFiles
        If CheckIfExist(fi.FullName.ToString.Replace("\" & fi.Name, "")) = False Then
            ListBox1.Items.Add(fi.FullName.ToString.Replace("\" & fi.Name, ""))
        End If
    Next
    
    Public Function CheckIfExist(ByRef Path As String) As Boolean
        Dim RetVal As Boolean = False
    
        For Each LI As String In ListBox1.Items
            If LI.ToString = Path Then
                RetVal = True
                Return RetVal
                Exit Function
            End If
        Next
        Return RetVal
    End Function
    

提交回复
热议问题