C# GetFiles with Date Filter
Here is a snippet using C# and LINQ, which will retrieve the files from a directory for a specific date
private static void GetFilesFromDirectory(string DirPath)
{
try
{
DirectoryInfo Dir = new DirectoryInfo(DirPath);
FileInfo[] FileList = Dir.GetFiles("*.*", SearchOption.TopDirectoryOnly );
var query = from FI in FileList
where FI.LastWriteTime.Date == DateTime.Now.Date
select FI.FullName + " " + FI.LastWriteTime;
foreach (string s1 in query )
{
Console.WriteLine(s1);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message );
}
}
Nice trick .. saved me lot of time. :) Thanks a lot.
ReplyDelete