Results 1 to 4 of 4

Thread: Read in directory content in name order

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2014
    Posts
    23

    Read in directory content in name order

    In a program I am developing the locations of a directory on my computer are read in to an array. However the files in the array are arbitrarily ordered.

    The code I have is:


    Directorycontents = Directory.GetFiles("pathname")

    how do make it so that they are sorted in order by file name?

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Read in directory content in name order

    Take a look at this:
    Code:
            Dim pn As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
            Dim somelist As List(Of String) = IO.Directory.GetFiles(pn).ToList
            somelist.Sort()
    
            For Each item As String In somelist
                Debug.WriteLine(item) 'full path
                Debug.WriteLine(IO.Path.GetFileName(item)) 'just file name
            Next
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2014
    Posts
    23

    Re: Read in directory content in name order

    I need a method that uses the current code I have sorry

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Read in directory content in name order

    It would help to see the code you have. Sorry I guessed.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Tags for this Thread

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