using Azylee.Core.DataUtils.CollectionUtils; using Azylee.Core.IOUtils.DirUtils; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace Azylee.Core.IOUtils.FileUtils { /// /// 文件搜索 /// public static class FileFinder { /// /// 获取文件(单层目录) /// /// 路径 /// 通配符 /// public static List GetFile(string path, string pattern = "*") { try { if (Directory.Exists(path)) { List result = Directory.EnumerateFiles(path, pattern).ToList(); return result; } } catch (Exception e) { } return null; } /// /// 获取所有目录中的所有文件 /// /// /// /// public static void GetAllFile(string path, Action> action, string[] patterns = null) { List allpath = DirFinder.GetAllPath(path); if (allpath == null) allpath = new List(); allpath.Add(path); foreach (var p in allpath) { if (Ls.Ok(patterns)) { foreach (var pattern in patterns) { List files = GetFile(p, pattern); if (Ls.Ok(files)) action?.Invoke(files); } } else { List files = GetFile(p); if (Ls.Ok(files)) action?.Invoke(files); } } } } }