FileTimeTool.cs 805 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. namespace Azylee.Core.IOUtils.FileUtils
  7. {
  8. public static class FileTimeTool
  9. {
  10. /// <summary>
  11. /// 检查文件创建至此已过n分钟
  12. /// </summary>
  13. /// <param name="fileName"></param>
  14. /// <returns></returns>
  15. public static double pastMinutes(string fileName)
  16. {
  17. double result = -1;
  18. if (File.Exists(fileName))
  19. {
  20. try
  21. {
  22. FileInfo fi = new FileInfo(fileName);
  23. result = (DateTime.Now - fi.CreationTime).TotalMinutes;
  24. }
  25. catch (Exception e) { }
  26. }
  27. return result;
  28. }
  29. }
  30. }