Mufasa said:
Is there an easy way to get the oldest file in a directory without having
to
go through all the files comparing the file modified time?
TIA - Jeff.
Here is a way to do this. Replace "c:\foo.txt" as needed.
class Program
{
static void Main ( string [ ] args )
{
Process p = new Process ();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = @"/c dir /B /OD > c:\foo.txt";
p.Start ();
p.WaitForExit ();
using (FileStream fs = new FileStream ( @"c:\foo.txt", FileMode.Open ))
{
TextReader tr = new StreamReader ( fs );
string txt = tr.ReadLine ();
Console.Out.WriteLine ( txt ); // txt has oldest filename
}
Console.In.ReadLine ();
}
}