Search Amazon:

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)
    Next
Sign In
  User Id 
  Password 


Submit Your Own Code and Articles




About TheScarms
About TheScarms

Ask me your programming questions

I read every email and answer all I can.

User Feedback: Be the first to add a comment! Items to Show:     

     
You must log in to post feedback.
Comment:    
 

If you use this code, please mention "www.TheScarms.com"

Email this page


TheScarms AppSentinel lets you securely copy protect and create evaluation versions of your software

TheScarms(tm) AppSentinel lets you quickly and easily create evaluation versions of your software and stop unauthorized copying and unregistered use of your programs!

Get your free
trial copy today!


      The World's Number 1 Web Host

© Copyright 2008 TheScarms