Subdirectories Learn programming Visual Basic (


Additional Libraries


Subdirectories 36


Create a program to store the files which are in a certain directory and its subdirectories.

Then, it will ask the user which text to search and it will display the files containing that text in their name.

Program will end when the user enters an empty search string.


Imports System
Imports System.IO

Class Subdirectories
    Private Shared Sub Main()
            Dim text As String = ""
            Console.Write("Enter a directory for search: ")
            text = Console.ReadLine()

            While text <> ""
                Dim directory As DirectoryInfo = New DirectoryInfo(text)
                Dim files As FileInfo() = directory.GetFiles("*.*")
                Dim directories As DirectoryInfo() = directory.GetDirectories()
                Dim i As Integer = 0

                While i < files.Length
                    Console.WriteLine((CType(files(i), FileInfo)).FullName)
                    i += 1
                End While

                For i = 0 To directories.Length - 1
                    Console.WriteLine((CType(directories(i), DirectoryInfo)).FullName)

                Console.Write(vbLf & "Enter a directory for search: ")
                text = Console.ReadLine()
            End While

        Catch ex As Exception
        End Try
    End Sub
End Class