Re: Getting Direcotry files sorted by date, is it possible?
From: Jonathan Stowe (jns_at_gellyfish.com)
Date: 02/16/05
- Next message: Alberto: "Re: Calendar"
- Previous message: Peter Jausovec: "Re: Calendar"
- In reply to: Raed Sawalha: "Getting Direcotry files sorted by date, is it possible?"
- Next in thread: Stefan L: "Re: Getting Direcotry files sorted by date, is it possible?"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 16 Feb 2005 15:12:30 +0000
Raed Sawalha <RaedSawalha@discussions.microsoft.com> wrote:
> I wondering if it possilble to get the directory files ordered by creation date
>
> string [] files = System.IO.Directory.GetFiles(strPath,"*.msg")
>
> can I sort the returned file by creation date?
>
You need to implement your own IComparer do the specialized sort:
using System;
using System.IO;
using System.Collections;
public class SortFiles
{
public class CompareFileByDate :IComparer
{
int IComparer.Compare(Object a, Object b)
{
FileInfo fia = new FileInfo((string)a);
FileInfo fib = new FileInfo((string)b);
DateTime cta = fia.CreationTime;
DateTime ctb = fib.CreationTime;
return DateTime.Compare(cta, ctb);
}
}
public static void Main()
{
string [] files = System.IO.Directory.GetFiles("..");
IComparer fileComparer = new CompareFileByDate();
Array.Sort(files, fileComparer);
foreach ( string f in files )
{
Console.WriteLine(f);
}
}
}
/J\
- Next message: Alberto: "Re: Calendar"
- Previous message: Peter Jausovec: "Re: Calendar"
- In reply to: Raed Sawalha: "Getting Direcotry files sorted by date, is it possible?"
- Next in thread: Stefan L: "Re: Getting Direcotry files sorted by date, is it possible?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|