Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Obtaining oldest file in a directory
Message
From
18/09/2008 13:15:06
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
To
18/09/2008 09:46:43
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01348390
Message ID:
01348682
Views:
18
>>Hi Tim,
>>
>>since you are only interested in the name you could modify the code like this:
>>
>>System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(@"C:\");
>>String name = info.GetFiles("*.jpg").OrderBy(x => x.LastWriteTime).First().Name;
>>
>>I'm not sure which date you want to check. LastWriteTime would be the time stamp you see in Explorer.
>
>I was wondering about the date but in our situation it isn't really that critical to get the oldest. I was just wanting to make and attempt to process the oldes and it appears at least from my testing that GetFiles() must get them in that order already. I tried several attempts to cause it to do different and it was pretty consistent about the [0] record being the oldest. I find linq interesting and using your example as well as Paul to learn and play with some.
>Thanks
>Tim

Well today it doesn't prove true as I am now getting the newest record first. Humph.. Guess I will try to use one of the other methods with linq. I don't understand why the same test today gives a different view as it did yesterday.
Tim
Timothy Bryan
Previous
Reply
Map
View

Click here to load this message in the networking platform