[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1794
  • Last Modified:

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
0
rpizzo
Asked:
rpizzo
2 Solutions
 
grayeCommented:
What is articleList ?  Perhaps a DataGridView? or ListView?
0
 
lazyberezovskyCommented:
Go this way
DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory);
FileInfo[] files = di.GetFiles();
Array.Reverse(files);
articleList.DataSource = files;

Open in new window

0
 
AkshCommented:
Hi rpizzo,

You may use Array.Reverse() method to cater the requirement.

Code: Check for the comment having the name Aksh.
===============================================
Dim dirInfo As New DirectoryInfo(strDir)
       Dim f() As FileInfo = dirInfo.GetFiles("*.*")  ''Aksh: Getting the information in an array
        Array.Reverse(f) 'Aksh: Reversing an array.
        articleList.DataSource = f 'Aksh: Binding reversed array to control
        Dim FileCount As Integer = dirInfo.GetFiles("*.*").Length
        articleList.DataBind()
===============================================

-Aksh
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
lazyberezovskyCommented:
VB for you
Dim files As FileInfo() = dirInfo.GetFiles()
Array.Reverse(files)
articleList.DataSource = files

Open in new window

0
 
PaulHewsCommented:
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
0
 
rpizzoAuthor Commented:
Te quick response was appreciated.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now