DirFinder.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Azylee.Core.DataUtils.CollectionUtils;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. namespace Azylee.Core.IOUtils.DirUtils
  8. {
  9. public class DirFinder
  10. {
  11. /// <summary>
  12. /// 获取目录下的目录(一层)
  13. /// </summary>
  14. /// <param name="path"></param>
  15. /// <returns></returns>
  16. public static List<string> GetPath(string path)
  17. {
  18. if (Directory.Exists(path))
  19. try { return Directory.EnumerateDirectories(path).ToList(); } catch (Exception e) { }
  20. return null;
  21. }
  22. /// <summary>
  23. /// 获取目录下所有目录(递归)
  24. /// </summary>
  25. /// <param name="path"></param>
  26. /// <returns></returns>
  27. public static List<string> GetAllPath(string path)
  28. {
  29. List<string> result = GetPath(path);
  30. if (Ls.Ok(result))
  31. {
  32. List<string> temp = new List<string>();
  33. foreach (var item in result)
  34. {
  35. List<string> t = GetAllPath(item);
  36. if (Ls.Ok(t)) temp.AddRange(t);
  37. }
  38. result.AddRange(temp);
  39. return result;
  40. }
  41. return null;
  42. }
  43. }
  44. }