यदि आप पुनरावर्ती खोज करना चाहते हैं, तो आप कोड के इस सुंदर टुकड़े का उपयोग कर सकते हैं:
public static FileInfo GetNewestFile(DirectoryInfo directory) {
return directory.GetFiles()
.Union(directory.GetDirectories().Select(d => GetNewestFile(d)))
.OrderByDescending(f => (f == null ? DateTime.MinValue : f.LastWriteTime))
.FirstOrDefault();
}
बस इसे निम्न तरीके से कॉल करें:
FileInfo newestFile = GetNewestFile(new DirectoryInfo(@"C:\directory\"));
और बस। एक FileInfo
उदाहरण देता है या null
यदि निर्देशिका खाली है।