Windows Phone Developers

Saturday, November 1, 2008

How to Filter files that are modified in a specific day using C#

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 );

}

}

Filter files by Date using C# GetFiles, DirectoryInfo.GetFiles method in C#, Filter files by date using DirectoryInfo, C# Get Files modified within a week, Filter files by Date using .NET GetFiles, DirectoryInfo.GetFiles method in .NET, Filter files by date using DirectoryInfo, .NET Get Files modified within a week Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

1 comment:

  1. Nice trick .. saved me lot of time. :) Thanks a lot.

    ReplyDelete