using System.IO;
public static void Main()
{
DirectoryInfo di = new DirectoryInfo("c:\\temp\\");
FileSystemInfo[] files = di.GetFileSystemInfos("*.mp3");
printFiles(files);
Array.Sort(files, CompareFileByDate);
printFiles(files);
}
public static int CompareFileByDate(FileSystemInfo f1, FileSystemInfo f2)
{
return DateTime.Compare(f1.LastWriteTime, f2.LastWriteTime);
}
public static void printFiles(FileSystemInfo[] files)
{
foreach(FileSystemInfo file in files)
{
Console.WriteLine(file.Name);
}
Console.WriteLine("********************************");
}
See if this helps you at all.
I have used LastWriteTime
property. You can choose whichever works for you (CreationTime
or LastAccessTime
).
EDIT: Sure, this can be converted to more compact syntax using c# 3.0 & support for lambda expressions.
EDIT2:
from file in new DirectoryInfo(@"c:\temp\").GetFileSystemInfos("*.mp3")
orderby file.LastWriteTime
select file
EDIT3: vb.net version of the above c# code
from file in new DirectoryInfo("c:\temp\").GetFileSystemInfos("*.mp3") _
order by file.LastWriteTime _
select file
EDIT4: Is this what you are looking for?
This will give you the max. date of the LastWriteTime of all *.mp3 files.
(from file in new DirectoryInfo("c:\temp\").GetFileSystemInfos("*.mp3") _
order by file.LastWriteTime descending _
select file.LastWriteTime).Take(1)
OR
(from file in new DirectoryInfo("c:\temp\").GetFileSystemInfos("*.mp3") _
select file.LastWriteTime).Max()