Link to home
Start Free TrialLog in
Avatar of rpizzo
rpizzoFlag for United States of America

asked on

How do I sort dirInfo.GetFiles("*.*") by name in reverse order?

I am displaying a list of files from a directory and they by default are displayed in alphabetical order ascending (A - Z) by filename.

I would like to reverse the order  (Z - A) on how they are displayed by filename.

Code I am currently using:
===============================================
Dim dirInfo As New DirectoryInfo(strDir)

        articleList.DataSource = dirInfo.GetFiles("*.*")
        Dim FileCount As Integer = dirInfo.GetFiles("*.*").Length
        articleList.DataBind()
===============================================

Any help would be appreciated, Thanks
Avatar of graye
graye
Flag of United States of America image

What is articleList ?  Perhaps a DataGridView? or ListView?
Go this way
DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory);
FileInfo[] files = di.GetFiles();
Array.Reverse(files);
articleList.DataSource = files;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Aksh
Aksh
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree with lazyberezovsky, but I would strongly suggest that you call Array.Sort on the array before calling Reverse.  

Directory.GetFiles does not guarantee that the files will be in any sorted order:

See remarks section
http://msdn.microsoft.com/en-us/library/07wt70x2.aspx
Avatar of rpizzo

ASKER

Te quick response was appreciated.