The code could look like this:
bool allFilesDeleted =
(from f in Directory.GetFiles(dirName)
let info = new FileInfo(f)
where info.LastAccessTime < 3.Months().Ago
select info.AsSideEffect(i=>i.Delete())
.All(success=>success);
Update:
LOL! Didn't expect such a negative reception, but people don't read anymore...I clearly stated that the code could look like this.
What is obviously missing in the .NET Framework is an Extension method "Months()" applicable to int that will return a date 3 months in the past. How this can work is shown here: http://realfiction.net/Content/Entry/77
What is also obviously missing is an extension method to perform a side-effect in LINQ which can look something like this:
public static bool AsSideEffect<T>(this T target, Action<T> action)
{
try
{
action(target);
return true;
}
catch (Exception x)
{
return false;
}
}
which would allow Binding a void method into the iteration of a LINQ expression. OMG guys, it's Monday, give it a rest!