Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Using Directory.GetFiles() WITH multiple extensions AND sort order

Using Directory.GetFiles() WITH multiple extensions AND sort order

Scheduled Pinned Locked Moved Visual Basic
questionalgorithmsdata-structuresperformancehelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jayme65
    wrote on last edited by
    #1

    Hi, I have to get a directory file list, filtered on multiple extensions...and sorted! I use this, which is the fastest way I've found to get dir content filtered on multiple extensions:

    Dim ext As String() = {"*.jpg", "*.bmp","*png"}
    Dim files As String() = ext.SelectMany(Function(f) Directory.GetFiles(romPath, f)).ToArray
    Array.Sort(files)

    and then use an array sort. I was wondering (and this is my question ;)) if there would be a way to do the sorting IN the same main line? A kind of:

    Dim files As String() = ext.SelectMany(Function(f) Directory.GetFiles(romPath, f)[B].Order By Name[/B]).ToArray

    and, if yes, if I would gain speed doing this instead of sorting the array at the end (but I would do my test and report..as soon as I get a solution!!)? Thanks for your help!!

    L 2 Replies Last reply
    0
    • J Jayme65

      Hi, I have to get a directory file list, filtered on multiple extensions...and sorted! I use this, which is the fastest way I've found to get dir content filtered on multiple extensions:

      Dim ext As String() = {"*.jpg", "*.bmp","*png"}
      Dim files As String() = ext.SelectMany(Function(f) Directory.GetFiles(romPath, f)).ToArray
      Array.Sort(files)

      and then use an array sort. I was wondering (and this is my question ;)) if there would be a way to do the sorting IN the same main line? A kind of:

      Dim files As String() = ext.SelectMany(Function(f) Directory.GetFiles(romPath, f)[B].Order By Name[/B]).ToArray

      and, if yes, if I would gain speed doing this instead of sorting the array at the end (but I would do my test and report..as soon as I get a solution!!)? Thanks for your help!!

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Jayme65 wrote:

      if there would be a way to do the sorting IN the same main line? A kind of:

      You can combine methods on a line, but that makes it a compound statement; it still execute a statement at a time. Getting a list and sorting are two distinctly different things.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      1 Reply Last reply
      0
      • J Jayme65

        Hi, I have to get a directory file list, filtered on multiple extensions...and sorted! I use this, which is the fastest way I've found to get dir content filtered on multiple extensions:

        Dim ext As String() = {"*.jpg", "*.bmp","*png"}
        Dim files As String() = ext.SelectMany(Function(f) Directory.GetFiles(romPath, f)).ToArray
        Array.Sort(files)

        and then use an array sort. I was wondering (and this is my question ;)) if there would be a way to do the sorting IN the same main line? A kind of:

        Dim files As String() = ext.SelectMany(Function(f) Directory.GetFiles(romPath, f)[B].Order By Name[/B]).ToArray

        and, if yes, if I would gain speed doing this instead of sorting the array at the end (but I would do my test and report..as soon as I get a solution!!)? Thanks for your help!!

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Jayme65 wrote:

        ext.SelectMany(Function(f) Directory.GetFiles(romPath, f))

        This part gets the list three times, and filters it three times. Next, you turn it into an array, and sort that. It'd (probably) be faster to get the list once and filter it. Since GetFiles already returns an array, there's no need to convert it.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups