I am using this to choose a root folder and take the newest file from each directory before adding this files into my listbox
but in some cases it does not choose the newest file.
var rootDirFile = Directory
.EnumerateFiles(pathToSearch, "*.doc", SearchOption.TopDirectoryOnly)
.OrderByDescending(f => File.GetLastWriteTime(f))
.Take(1);
var allNewestFilesOfEachFolder = Directory
.EnumerateDirectories(pathToSearch, "*.*", SearchOption.AllDirectories)
.Select(d => Directory.EnumerateFiles(d, "*.doc")
.OrderByDescending(f => File.GetLastWriteTime(f))
.FirstOrDefault());
foreach (string tempFile in rootDirFile.Concat(allNewestFilesOfEachFolder))
{
//add the file
}