4.using System.Diagnostics;
5.
6.namespace test01
7.{
8. class Program
9. {
10. private string _sFilePath;
11. public Program(string sFilePath)
12. {
13. _sFilePath = sFilePath;
14. }
15. public void GetFileVersion()
16. {
17. Regex regex = new Regex(@"\\");
18. string[] arrTemp = regex.Split(_sFilePath);
19. String sFilePathNew = null;
20. foreach (string s in arrTemp)
21. {
22. sFilePathNew = sFilePathNew + @"\\" + s;
23. sFilePathNew = sFilePathNew.TrimStart('\\');
24. }
25. FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(sFilePathNew);
26. Console.WriteLine("File: " + myFileVersionInfo.FileDescription + '\n' + "Version number: " + myFileVersionInfo.FileVersion);
27. }
28. static void Main(string[] args)
29. {
30. Program p = new Program(args[0]);
31. p.GetFileVersion();
32. Console.ReadKey();
33. }
34. }
35.}
文章来源于领测软件测试网 https://www.ltesting.net/