June 29th, 2008, 12:48 AM
|
#1 (permalink)
|
| Ultimate Member
Join Date: Oct 2001
Posts: 20,458
|
ok i know I can do this with a List.Sort or with a crappy bubble sort loop.. but thats not nearly enough fun
So I'm trying to use LINQ which is supposed to be great for this stuff
So ultimate goal is to connect to a directory of a lot of files and get the oldest .log file w/o doing any loops.
So far I have Code: namespace PollExchangeProperties
{
class Program
{
static void Main(string[] args)
{
DirectoryInfo di = new DirectoryInfo(@"C:\code\");
foreach (DirectoryInfo d in di.GetDirectories())
{
Console.WriteLine("Directory: {0}", d.Name);
Console.WriteLine("# Files: {0}", d.GetFiles("*").Length );
foreach (FileInfo f in d.GetFiles())
{
Console.WriteLine("FileName: {0}\\{1} = {2} kb", d.Name, f.Name, f.Length/1024);
}
}
}
}
} This obviously uses a loop, but this is just for testing
So basically I want to do this
GetDirectory
Get all *.log files in directory and return date of oldest file in that directory
Yes I know it can be done with bat easily, but again thats not a challenge
This is a great excercise for me to learn C#  |
| |