From 888415867afb5aca506468d5b04f98a66ba1ab4a 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 08:21:23 +0800 Subject: [PATCH] =?UTF-8?q?ref:=20EnumerateFiles=E3=80=81EnumerateDirector?= =?UTF-8?q?ies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Shared/Utils/DirectoryUtils.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Shared/Utils/DirectoryUtils.cs b/Shared/Utils/DirectoryUtils.cs index fdd24c7..48fbaec 100644 --- a/Shared/Utils/DirectoryUtils.cs +++ b/Shared/Utils/DirectoryUtils.cs @@ -13,11 +13,28 @@ public static class DirectoryUtils { /// /// 判断文件夹是否存在。 /// - public static bool Exists(string path) => Directory.Exists(PathUtils.ToLongPath(path)); + public static bool Exists(string path) => + Directory.Exists(PathUtils.ToLongPath(path)); /// /// 创建 对象。 /// - public static DirectoryInfo GetInfo(string path) => new(PathUtils.ToLongPath(path)); + public static DirectoryInfo GetInfo(string path) => + new(PathUtils.ToLongPath(path)); + /// + /// 返回指定路径下的所有文件。 + /// + public static IEnumerable EnumerateFiles(string path, string searchPattern = "*", bool topDirectoryOnly = false) { + if (!Exists(path)) return []; + return Directory.EnumerateFiles(PathUtils.ToLongPath(path), searchPattern, topDirectoryOnly ? SearchOption.TopDirectoryOnly : SearchOption.AllDirectories); + } + + /// + /// 返回指定路径下的所有文件夹。 + /// + public static IEnumerable EnumerateDirectories(string path, string searchPattern = "*", bool topDirectoryOnly = false) { + if (!Exists(path)) return []; + return Directory.EnumerateDirectories(PathUtils.ToLongPath(path), searchPattern, topDirectoryOnly ? SearchOption.TopDirectoryOnly : SearchOption.AllDirectories); + } }