Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vb.net how to loop through a directory listing?

Tags:

vb.net

How can I loop through a folder getting each file listed and when its date/time?

like image 910
Alex Avatar asked Feb 07 '10 05:02

Alex


1 Answers

Use DirectoryInfo.GetFiles() and extract the data (Name, CreationTime, etc.) from the FileInfo class.

I've pasted some code from the MSDN page here.

Imports System
Imports System.IO
Public Class GetFilesTest
    Public Shared Sub Main()
        ' Make a reference to a directory.
        Dim di As New DirectoryInfo("c:\")
        ' Get a reference to each file in that directory.
        Dim fiArr As FileInfo() = di.GetFiles()
        ' Display the names of the files.
        Dim fri As FileInfo
        For Each fri In fiArr
            Console.WriteLine(fri.Name)
        Next fri
    End Sub 'Main
End Class 'GetFilesTest
like image 61
micahtan Avatar answered Sep 16 '22 15:09

micahtan