Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

C# .Net 2.0 DirectoryInfo GetFiles Order?

  • 17-10-2012 05:24PM
    #1
    Registered Users, Registered Users 2 Posts: 7,546 ✭✭✭


    Hi Just looking into something at the moment.

    in .Net 2.0 i cant find any documentation to say what order files are returned in with the DirectoryInfo().GetFiles().

    A bit of testing seems to indicate its returned in order of name but in 4.5 documentation it supports this testing but also says that its not guaranteed.

    Anyone shed some light on this and what could cause the order to change?

    Im aware that in later versions i can sort the result but the project is in 2.0 for a reason.

    Thanks for any help.


Comments

  • Administrators Posts: 55,580 Admin ✭✭✭✭✭awec


    You can sort the result in .NET 2.0 as well:

    FileInfo[] files = DirectoryInfo().GetFiles(); // this is wrong but you know what I mean
    Array.Sort(files, new delegate(FileInfo file1, FileInfo file2))
    {
    return file1.Name.CompareTo(file2.Name);
    });

    Later versions for the most part just make the code to do it prettier.


  • Registered Users, Registered Users 2 Posts: 7,546 ✭✭✭BrokenArrows


    awec wrote: »
    You can sort the result in .NET 2.0 as well:

    FileInfo[] files = DirectoryInfo().GetFiles(); // this is wrong but you know what I mean
    Array.Sort(files, new delegate(FileInfo file1, FileInfo file2))
    {
    return file1.Name.CompareTo(file2.Name);
    });

    Later versions for the most part just make the code to do it prettier.

    Ah ok. Cool.

    Thanks.


Advertisement