List all files in a folder with VB.NET

In .NET you can use the DirectoryInfo class of the System.IO namespace to get a list of files in a particular folder. DirectoryInfo has a GetFiles method that returns a file list, as FileInfo structures, from the specified directory. Optionally, GetFiles takes a pattern as a parameter that can limit the list of files returned.

    Imports System.IO
    Dim strFileSize As String = ""
    Dim di As New IO.DirectoryInfo("C:\temp")
    Dim aryFi As IO.FileInfo() = di.GetFiles("*.txt")
    Dim fi As IO.FileInfo

    For Each fi In aryFi
        strFileSize = (Math.Round(fi.Length / 1024)).ToString()
        Console.WriteLine("File Name: {0}", fi.Name)
        Console.WriteLine("File Full Name: {0}", fi.FullName)
        Console.WriteLine("File Size (KB): {0}", strFileSize )
        Console.WriteLine("File Extension: {0}", fi.Extension)
        Console.WriteLine("Last Accessed: {0}", fi.LastAccessTime)
        Console.WriteLine("Read Only: {0}", (fi.Attributes.ReadOnly = True).ToString)

About TheScarms
About TheScarms

Sample code
version info

If you use this code, please mention ""

Email this page

© Copyright 2024 TheScarms
Goto top of page