In this post we will see a VB.Net Program to retrieve list of file names with full path in a given folder/directory.


Imports System.IO

Module Module1

    Sub Main()
            Dim FolderPath As String
            Dim Files As String() 'string array
            Console.WriteLine(vbLf & ">>>VB.NET PROGRAM To PRINT FULL FILES PATH IN A Given Directory  <<<")
            Console.WriteLine(vbLf & "Enter the Directory Path to get File Names in it : ")
            FolderPath = Console.ReadLine()
            Files = Directory.GetFiles(FolderPath)
            Console.WriteLine(vbLf & " The FilePaths in given Directory are : " & vbLf & vbLf)
            For Each FileName As String In Files
        Catch ex As DirectoryNotFoundException 'catching directory not found exception
            Console.BackgroundColor = ConsoleColor.Red
            Console.WriteLine(vbLf & vbLf & " Directory Not Found..Press any key to exit...")
        Catch ex As Exception 'catching all other exceptions
            Console.BackgroundColor = ConsoleColor.Red
            Console.WriteLine(vbLf & vbLf & ex.Message)
        End Try
    End Sub

End Module
Sample Output : 
VB NET File Paths in folder

Leave a Reply

Your email address will not be published.