locked
Retriving File name from a folder RRS feed

  • Question

  • hi everybody,
                    Can any one please let me know, how to retrive the file names from a folder. I have already counted the files. I need the code for retriving the counted file names and storing it in a array.


    Thanks in advance,
    Suresh
    Tuesday, July 1, 2008 12:14 PM

Answers

  • You can just create a list of string, and fill it with the file names by making a call to the GetFiles method in the My helper namespace.

    Dim myFileNames As New List(Of String)(My.Computer.FileSystem.GetFiles("C:\some directory\"))  
     
     

    Here is some usage


            For Each fileName As String In myFileNames  
                Debug.WriteLine(fileName)  
            Next 
     
            'PUT IN ARRAY IF NEEDED  
            Dim myArray() As String = myFileNames.ToArray 


    Matt Kleinwaks - MSMVP MSDN Forums Moderator - www.zerosandtheone.com - visit my website for a chance to win an MSDN subscription.
    Tuesday, July 1, 2008 2:04 PM
    Moderator

All replies

  • You can just create a list of string, and fill it with the file names by making a call to the GetFiles method in the My helper namespace.

    Dim myFileNames As New List(Of String)(My.Computer.FileSystem.GetFiles("C:\some directory\"))  
     
     

    Here is some usage


            For Each fileName As String In myFileNames  
                Debug.WriteLine(fileName)  
            Next 
     
            'PUT IN ARRAY IF NEEDED  
            Dim myArray() As String = myFileNames.ToArray 


    Matt Kleinwaks - MSMVP MSDN Forums Moderator - www.zerosandtheone.com - visit my website for a chance to win an MSDN subscription.
    Tuesday, July 1, 2008 2:04 PM
    Moderator
  • hi,
       As i am new to VB. I couldnt able to frame the code. I tried but its giving error msg (complile Error). Could you please give me exact code structure to get the file names in a folder and storing the names in the array. Please give as soon as possible. Its quite urgent.

    Thanks in advance,
    Suresh M J
    Wednesday, July 2, 2008 6:55 AM