Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C# .Net 2.0 DirectoryInfo GetFiles Order?

  • 17-10-2012 4:24pm
    #1
    Registered Users, Registered Users 2 Posts: 7,501 ✭✭✭


    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: 54,423 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,501 ✭✭✭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