c# - How to find the most recent file in a directory using .NET, and without looping? -
I have to find the most recently modified file in a directory.
I know that I can loop through each file in a folder and compare File.GetLastWriteTime
, but without any looping There is a better way.
How about something like this ...
Var directory = new DirectoryInfo ("C: \\ MyDirectory"); Var myFile = (f.LastWriteTime descending selection in order from f.files (in directory) f). first (); // or ... var myFile = directory.GetFiles (). Orderbidesigning (f => f.LastWriteTime). first ();
Comments
Post a Comment