2 Replies - 1348 Views - Last Post: 01 September 2013 - 03:49 AM Rate Topic: -----

#1 Jayme65  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-September 12

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

Posted 01 September 2013 - 03:06 AM

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).Order By Name).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!!

This post has been edited by andrewsw: 01 September 2013 - 03:44 AM


Is This A Good Question/Topic? 0
  • +

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

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3838
  • View blog
  • Posts: 13,595
  • Joined: 12-December 12

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

Posted 01 September 2013 - 03:47 AM

It can probably be done but why would you want to reduce two understandable statements into one, confusing, statement?

Perhaps

Dim files As String() = Array.sort(ext.SelectMany(Function(f) Directory.GetFiles(romPath, f)).ToArray)

but I wouldn't bother.

And, no, you will not see a speed benefit. Logically, the array has to be created, and filled, before being sorted.

This post has been edited by andrewsw: 01 September 2013 - 03:49 AM

Was This Post Helpful? 0
  • +
  • -

#3 Jayme65  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 19-September 12

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

Posted 01 September 2013 - 03:49 AM

You're right Andrew, using

myFiles = myExtensions.SelectMany(Function(ext) Directory.GetFiles(myPath, ext)).OrderBy(Function(x) x).ToArray


..is insignificant!

On 20000 files, an average of 0.17 sec instead of and average of 0.18 sec !!

Thanks!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1