Last active
August 29, 2015 14:14
-
-
Save borismod/2b89eae39110a1c507c1 to your computer and use it in GitHub Desktop.
List files recursively with their max version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Windows.Forms; | |
| using System.IO; | |
| using System.Linq; | |
| using System.Diagnostics; | |
| class Script | |
| { | |
| static public void Main(string[] args) | |
| { | |
| if (args == null || args.Length < 1 ) | |
| { | |
| Console.WriteLine("Specify path to find files" ); | |
| return; | |
| } | |
| var directory = args[0]; | |
| var filesWithVersions = Directory.EnumerateFiles(directory, "*.*", SearchOption.AllDirectories) | |
| .Select(f => new {FileName = Path.GetFileName(f), Version = FileVersionInfo.GetVersionInfo(f)}) | |
| .Where(f => f.Version.ProductVersion != null) | |
| .GroupBy(f => f.FileName) | |
| .Select(g => new {FileName = g.Key, MaxVersion = g.Max(r => r.Version.ProductVersion)}) | |
| .ToList(); | |
| foreach (var filesWithVersion in filesWithVersions) | |
| { | |
| Console.WriteLine("{0}\t{1}", filesWithVersion.FileName, filesWithVersion.MaxVersion); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment