FilePathUtil.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.IO;
  3. namespace Update.Util
  4. {
  5. /// <summary>
  6. /// 文件路径工具
  7. /// </summary>
  8. public static class FilePathUtil
  9. {
  10. //基目录,格式:C:\WorkDir
  11. private static readonly string m_BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
  12. /// <summary>
  13. /// 获取绝对路径所在目录
  14. /// </summary>
  15. /// <param name="absolutePath">绝对路径</param>
  16. /// <returns>所在目录</returns>
  17. public static string GetDirectoryName(string absolutePath)
  18. {
  19. return Path.GetDirectoryName(absolutePath);
  20. }
  21. /// <summary>
  22. /// 获取文件的绝对路径(相对于当前基目录)
  23. /// </summary>
  24. /// <param name="relativePath">相对路径</param>
  25. /// <returns>绝对路径</returns>
  26. public static string GetAbsolutePath(string relativePath)
  27. {
  28. return GetAbsolutePath(relativePath, m_BaseDirectory);
  29. }
  30. /// <summary>
  31. /// 获取文件的绝对路径
  32. /// </summary>
  33. /// <param name="relativePath">相对路径</param>
  34. /// <param name="basePath">基路径</param>
  35. /// <returns>绝对路径</returns>
  36. public static string GetAbsolutePath(string relativePath, string basePath)
  37. {
  38. return Path.Combine(basePath, relativePath).Replace('/', '\\');
  39. }
  40. }
  41. }