DirectoryUtils.cs 760 B

1234567891011121314151617181920212223
  1. namespace MeloongCore;
  2. public static class DirectoryUtils {
  3. /// <summary>
  4. /// 创建文件夹,或文件所在的文件夹。
  5. /// 文件夹已存在时不会抛出异常。
  6. /// </summary>
  7. public static void Create(string path, bool isFilePath = false) {
  8. if (isFilePath) path = Path.GetDirectoryName(path);
  9. Directory.CreateDirectory(PathUtils.ToLongPath(path));
  10. }
  11. /// <summary>
  12. /// 判断文件夹是否存在。
  13. /// </summary>
  14. public static bool Exists(string path) => Directory.Exists(PathUtils.ToLongPath(path));
  15. /// <summary>
  16. /// 创建 <see cref="DirectoryInfo"/> 对象。
  17. /// </summary>
  18. public static DirectoryInfo GetInfo(string path) => new(PathUtils.ToLongPath(path));
  19. }