Searching for files - what sets the return order?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

string[] allFiles = Directory.GetFiles(folderPath, filters,
SearchOption.AllDirectories);

I noticed that the order that the files are returned in varies from PC
to PC - some return in alphabetical order; some appear to return in
date modified or something else. In my testing, it seemed that files
within a give subdirectory are returned in alphabetical order, but its
the order that the subfolders themselves are processed in which varies
a lot.

Any thoughts?
 
Any thoughts?

Don't write code that depends on the order. If you need them in a
specific order you should sort the list youself.


Mattias
 
Mattias said:
Don't write code that depends on the order. If you need them in a
specific order you should sort the list youself.


Mattias

Yes - I have realised this, and will ensure that any code written will
sort the returned files. However, for an existing problem, I am
looking to give people an interim fix. If we can understand what sets
the return order, then perhaps this will help.
 
The return order is undefined and depends on the internal implementation of
the filesystem.
You should never rely on the order.

Don't write code that depends on the order. If you need them in a
specific order you should sort the list youself.


Mattias

Yes - I have realised this, and will ensure that any code written will
sort the returned files. However, for an existing problem, I am
looking to give people an interim fix. If we can understand what sets
the return order, then perhaps this will help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top