From 5790d01195bdaded321a5538f7ec8419e13ddde9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=BE=99=E8=85=BE=E7=8C=AB=E8=B7=83?= <1043137532@qq.com>
Date: Mon, 4 May 2026 10:29:10 +0800
Subject: [PATCH] ref: Directory
---
Shared/Utils/DirectoryUtils.cs | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/Shared/Utils/DirectoryUtils.cs b/Shared/Utils/DirectoryUtils.cs
index c472731..377d721 100644
--- a/Shared/Utils/DirectoryUtils.cs
+++ b/Shared/Utils/DirectoryUtils.cs
@@ -25,7 +25,7 @@ public static class DirectoryUtils {
///
/// 返回指定路径下的所有文件。
///
- public static IEnumerable EnumerateFiles(string path, string searchPattern = "*", bool topDirectoryOnly = false) {
+ public static IEnumerable EnumerateFiles(string path, bool topDirectoryOnly = false, string searchPattern = "*") {
if (!Exists(path)) return [];
return Directory.EnumerateFiles(PathUtils.ToLongPath(path), searchPattern, topDirectoryOnly ? SearchOption.TopDirectoryOnly : SearchOption.AllDirectories);
}
@@ -34,8 +34,26 @@ public static class DirectoryUtils {
/// 返回指定路径下的所有文件夹。
/// 路径不以分隔符结尾。
///
- public static IEnumerable EnumerateDirectories(string path, string searchPattern = "*", bool topDirectoryOnly = false) {
+ public static IEnumerable EnumerateDirectories(string path, bool topDirectoryOnly = false, string searchPattern = "*") {
if (!Exists(path)) return [];
return Directory.EnumerateDirectories(PathUtils.ToLongPath(path), searchPattern, topDirectoryOnly ? SearchOption.TopDirectoryOnly : SearchOption.AllDirectories);
}
+
+ ///
+ /// 该文件夹是否为空。
+ /// 如果文件夹不存在,也返回 true。
+ ///
+ public static bool IsEmpty(string path) {
+ if (!Exists(path)) return true;
+ return !Directory.EnumerateFileSystemEntries(PathUtils.ToLongPath(path)).Any();
+ }
+
+ ///
+ /// 剪切文件夹。
+ ///
+ public static void Move(string sourceDirName, string destDirName) {
+ if (!Exists(sourceDirName)) return;
+ Create(destDirName);
+ Directory.Move(PathUtils.ToLongPath(sourceDirName), PathUtils.ToLongPath(destDirName));
+ }
}