'Find the most recent file saved under same name but in different directories using .NET C#
The directories are the 3 below
filename = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
filenameprint = System.Environment.CurrentDirectory;
pathload = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
And the file is saved as printout.pdf in all the 3 directories.
I'm thinking of using the LastWriteTime function but I do not know how to stack for the latest.
Solution 1:[1]
This should do the trick:
var files = new List<string>() {filename, filenameprint, pathload};
var newestFile = files.Select(file => new FileInfo(file)).OrderByDescending(f => f.LastWriteTime).First();
Edit: naturally you will have to combine the filename with the paths, otherwise this does not make much sense.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pharnax |
