Results 1 to 5 of 5

Thread: [RESOLVED] Finding the file-list of all files contained in a Folder

  1. #1

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Resolved [RESOLVED] Finding the file-list of all files contained in a Folder

    Does anyone know how to find the list of files from a folder in a directory?

    Jennifer

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Finding the file-list of all files contained in a Folder

    An easy way would to use the DirectoryInfo class.
    Code:
            		//get the Folder
    		System.IO.DirectoryInfo myFolder = new System.IO.DirectoryInfo(@"C:\");
    		//loop through each file and delete
    		foreach (System.IO.FileInfo hFile in myFolder.GetFiles())
    			MesssageBox.Show(hFile.Name);
    Edit--
    Did I post VB.NET Code?
    Last edited by Shuja Ali; Mar 28th, 2006 at 07:10 AM. Reason: Posted VB Code earlier.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Finding the file-list of all files contained in a Folder

    I see a lot of people recommend the use of the DirectoryInfo and FileInfo classes for this type of thing. While there is nothing really wrong with that, I'd consider it preferable to use the Directory and File classes. These two classes have all static members and thus do not require creation of an instance. Unless you need the extra functionality provided by the FileInfo class, like file size, I'd suggest going with the more efficient option.
    Code:
    foreach (string filePath in Directory.GetFiles(@"C:\"))
    {
        MessageBox.Show(filePath)
    }
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Finding the file-list of all files contained in a Folder

    Agreed.
    I had this code handy as I have to do other stuff with the Files. So I just posted that with a small change.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  5. #5

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Finding the file-list of all files contained in a Folder

    Thanks Guys, its worked fine!!!!! - jennifer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width