FileInfo - how is it sorted?
FileInfo - how is it sorted?
FileInfo - how is it sorted?
FileInfo - how is it sorted?
FileInfo - how is it sorted?
FileInfo - how is it sorted? FileInfo - how is it sorted? FileInfo - how is it sorted? FileInfo - how is it sorted? FileInfo - how is it sorted? FileInfo - how is it sorted? FileInfo - how is it sorted? FileInfo - how is it sorted?
FileInfo - how is it sorted? FileInfo - how is it sorted?
FileInfo - how is it sorted?
Go Back  Xtreme Visual Basic Talk > > > FileInfo - how is it sorted?


Reply
 
Thread Tools Display Modes
  #1  
Old 01-30-2005, 01:35 AM
Jeff_B Jeff_B is offline
Centurion
 
Join Date: Apr 2004
Location: Canada / Germany
Posts: 108
Question FileInfo - how is it sorted?


I have a question concerning the Directoryinfo/FileInfo, given the example below:

Dim FI() As IO.FileInfo = DI.GetFiles
Dim File As IO.FileInfo
For Each File In FI
ListView1.Items.Add(File.Name)
Next

how is the order of the list determined? Are the files listed according to size, date, last accessed?

I need a way to list the files by the oldest one first. Does the FileInfo class have a sort method??

Thanks, Jeff
Reply With Quote
  #2  
Old 01-30-2005, 10:13 AM
MKoslof's Avatar
MKoslofFileInfo - how is it sorted? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

You can use a SortedList and provide a Comparer Object that does the correct comparison. Basically you can create a class that implements IComparer: And pass the sorted list into this function:

Code:
Public Class DateComparer : Implements IComparer Public Function Compare(ByVal x As Object, ByVal y As Object) As Int32 Implements IComparer.compare Dim fi = x.FileInfo Dim fy = y.FileInfo Dim xi As DateTime = fi.LastAccessTime Dim yi As DateTime = fy.LastAccessTime If x.Equals(y) Then Return 0 ElseIf (x < y) Then Return -1 Else Return +1 End If End Function

If you do some research regarding SortedLists and Icomparer, you will get the exact logic to meet your needs.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown

Last edited by MKoslof; 01-30-2005 at 10:34 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
FileInfo - how is it sorted?
FileInfo - how is it sorted?
FileInfo - how is it sorted? FileInfo - how is it sorted?
FileInfo - how is it sorted?
FileInfo - how is it sorted?
FileInfo - how is it sorted? FileInfo - how is it sorted? FileInfo - how is it sorted? FileInfo - how is it sorted? FileInfo - how is it sorted? FileInfo - how is it sorted? FileInfo - how is it sorted?
FileInfo - how is it sorted?
FileInfo - how is it sorted?
 
FileInfo - how is it sorted?
FileInfo - how is it sorted?
 
-->