Quantcast
Channel: Thom Robbins .NET Weblog
Viewing all articles
Browse latest Browse all 18

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

$
0
0

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


Viewing all articles
Browse latest Browse all 18

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>