How the files are ordered?

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

Guest

Hello, friends,

In the following source code,

DirectoryInfo dirCustom = new DirectoryInfo(filePath);
FileInfo[] files;

files = dirCustom.GetFiles("*.jpg");

When I use foreach loop to enumerate each file in files, what order shall I
get? Ordered by file name, modified date, file size, etc., or randomly?

Thanks a lot.
 
Andrew said:
In the following source code,

DirectoryInfo dirCustom = new DirectoryInfo(filePath);
FileInfo[] files;

files = dirCustom.GetFiles("*.jpg");

When I use foreach loop to enumerate each file in files, what order shall I
get? Ordered by file name, modified date, file size, etc., or randomly?

There's nothing in the documentation to specify what order they're
returned in, so I wouldn't make any assumptions - in particular, don't
make the assumption that the order they're returned in now will be the
order they're returned in for a future version of .NET.
 
Andrew said:
Hello, friends,

In the following source code,

DirectoryInfo dirCustom = new DirectoryInfo(filePath);
FileInfo[] files;

files = dirCustom.GetFiles("*.jpg");

When I use foreach loop to enumerate each file in files, what order shall
I
get? Ordered by file name, modified date, file size, etc., or randomly?


Sort the Fileinfo objects in the array if you need them in some kind of
order.
http://www.asp101.com/articles/christopher/filesystem/default.asp
 
Back
Top