rpizzo
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("*.*").Le ngth
articleList.DataBind()
========================== ========== ========== =
Any help would be appreciated, Thanks
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("*.*").Le
articleList.DataBind()
==========================
Any help would be appreciated, Thanks
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;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
Te quick response was appreciated.