ref: EnumerateFiles、EnumerateDirectories
This commit is contained in:
1 parent
9bfa70dc8d
commit
888415867a
1 file changed
+19
-2
@@ -13,11 +13,28 @@ public static class DirectoryUtils {
|
||||
/// <summary>
|
||||
/// 判断文件夹是否存在。
|
||||
/// </summary>
|
||||
public static bool Exists(string path) => Directory.Exists(PathUtils.ToLongPath(path));
|
||||
public static bool Exists(string path) =>
|
||||
Directory.Exists(PathUtils.ToLongPath(path));
|
||||
|
||||
/// <summary>
|
||||
/// 创建 <see cref="DirectoryInfo"/> 对象。
|
||||
/// </summary>
|
||||
public static DirectoryInfo GetInfo(string path) => new(PathUtils.ToLongPath(path));
|
||||
public static DirectoryInfo GetInfo(string path) =>
|
||||
new(PathUtils.ToLongPath(path));
|
||||
|
||||
/// <summary>
|
||||
/// 返回指定路径下的所有文件。
|
||||
/// </summary>
|
||||
public static IEnumerable<string> EnumerateFiles(string path, string searchPattern = "*", bool topDirectoryOnly = false) {
|
||||
if (!Exists(path)) return [];
|
||||
return Directory.EnumerateFiles(PathUtils.ToLongPath(path), searchPattern, topDirectoryOnly ? SearchOption.TopDirectoryOnly : SearchOption.AllDirectories);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回指定路径下的所有文件夹。
|
||||
/// </summary>
|
||||
public static IEnumerable<string> EnumerateDirectories(string path, string searchPattern = "*", bool topDirectoryOnly = false) {
|
||||
if (!Exists(path)) return [];
|
||||
return Directory.EnumerateDirectories(PathUtils.ToLongPath(path), searchPattern, topDirectoryOnly ? SearchOption.TopDirectoryOnly : SearchOption.AllDirectories);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user