Results 1 to 8 of 8

Thread: [RESOLVED] [2005] How to get list of files under selected folder ??

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    63

    Resolved [RESOLVED] [2005] How to get list of files under selected folder ??

    Hi!
    I am required to acquire the filenames of all the bitmap (.bmp) files inside a folder which is selected by the user.

    I am using the FolderBrowserDialog to recieve the path of the selected folder but i dont know how to get to the files inside the folder. I think that the filenames can be stored in an Array but i am not able to do it. Can anyone please me out..

    Please gimme the code if you can.. thx


    cheers
    Abhilash

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

    Re: [2005] How to get list of files under selected folder ??

    IO.File.GetFiles
    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

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    63

    Re: [2005] How to get list of files under selected folder ??

    Hey
    I dont know how to use that command.. i tried looking at the msdn library but nothing comes up.. can u tell me how to use IO.File.GetFiles


    cheers
    Abhilash

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

    Re: [2005] How to get list of files under selected folder ??

    Put file.getfiles into the MSDN library index and it will come up. If you include the leading IO it won't, but you should include the IO namespace when you use it in code.
    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

  5. #5
    Registered User RaviIntegra's Avatar
    Join Date
    Mar 2007
    Location
    Pondicherry, India
    Posts
    125

    Re: [2005] How to get list of files under selected folder ??

    vb Code:
    1. 'This code will work to get all the file names in your directory
    2.         Dim path As String = "E:\pictures"
    3.         Dim file_name() As String = {}
    4.         Dim i As Integer = 0
    5.         Dim fld As New System.IO.DirectoryInfo(path)
    6.         Dim fil As System.IO.FileInfo
    7.         ReDim file_name(fld.GetFiles("*.bmp").Length - 1)
    8.         For Each fil In fld.GetFiles("*.bmp")
    9.             file_name(i) = fil.Name
    10.             i = i + 1
    11.         Next

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    63

    Re: [2005] How to get list of files under selected folder ??

    Hey Ravi!
    The code you sent works perfect.. is thr a way to remove the extension name and get only the filename.. i need it to compare with another record.. so i need only the filename without extension... please Advise


    cheers
    Abhilash

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

    Re: [2005] How to get list of files under selected folder ??

    vb Code:
    1. For Each filePath As String In IO.Directory.GetFiles("folder path here", "*.bmp")
    2.     MessageBox.Show(IO.Path.GetFileNameWithoutExtension(filePath)
    3. Next 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

  8. #8

    Thread Starter
    Member
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    63

    Re: [2005] How to get list of files under selected folder ??

    Hey..
    your method works fine... thx a lot


    cheers
    Abhilash

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