Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting newest Excel filename from folder
Message
From
25/01/2007 17:42:18
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
22/01/2007 15:23:19
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB.NET 1.1
Miscellaneous
Thread ID:
01187847
Message ID:
01189408
Views:
6
>I have a folder with many Excel files. What would be the most elegant way to get the filename of the newest file? I know I can cycle through all the files and do a compare on the dates, but since I am going to be running this on a web server I am afraid that will incur too much overhead.
>
>Thanks for any advice!

Wish it were 2.0:) You can use Array.Sort with an IComparer. ie:
 DirectoryInfo di = new DirectoryInfo(stringPath);
 FileInfo[] fi = di.GetFiles("*.xls");
 MyComparer mc = new MyComparer();
 Array.Sort(fi, mc);
 // fi[0] is last written after sort

public class MyComparer:IComparer
{
   public int Compare(object x, object y)
   {
     return ((FileInfo)y).LastWriteTime.CompareTo( ((FileInfo)x).LastWriteTime );
   }
}
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform