Share via


A simple example of using the System.IO.DirectoryInfo Class

The System.IO.DirectoryInfo class exposes methods for creating, moving, and enumerating through directories and subdirectories.

For example the following simple console app allows you to loop through a specified directory and pull out the files and directories contained in it.

Imports System.io

Module Module1

    Sub Main()

        Dim di As New DirectoryInfo("c:\")

        Dim lFiles As FileInfo() = di.GetFiles("*.*")

        Dim fi As System.IO.FileSystemInfo

        ' get the files in the directory

        For Each fi In lFiles

            Console.WriteLine("File: " + fi.FullName)

        Next

        Console.WriteLine("------------------")

        For Each fi In di.GetDirectories()

            Console.WriteLine("Directory: " + fi.FullName)

        Next

        Console.ReadKey()

    End Sub

End Module

When run outputs the following