that’s what i try but it return only the newest file from only the top directories under the root
if(Directory.Exists("YourPath"))
foreach (string _tempFiles in Directory.GetDirectories("YourPath")
.Select(directory => Directory.GetFiles(directory, "*.*", SearchOption.AllDirectories)
.OrderByDescending(File.GetLastWriteTime)
.FirstOrDefault()))
This returns all newest files of each directory(including root):
If there’s no file in a directory the file is
null, so the number of files is equal to the number of folders.Note that Linq is not the right tool for
System.IOsince error-handling is difficult.