DierctoryHelper.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. namespace Universal;
  2. public class DierctoryHelper
  3. {
  4. public static bool GetAllFiles(string folderPath, out List<string>? files, string? extenionType = null)
  5. {
  6. files = default;
  7. List<FileInfo> fileInfo;
  8. List<string>? tempFiles = [];
  9. try
  10. {
  11. DirectoryInfo folder = new(folderPath);
  12. fileInfo = [.. folder.GetFiles()];
  13. }
  14. catch
  15. {
  16. return false;
  17. }
  18. if (fileInfo is null || fileInfo.Count == 0)
  19. return true;
  20. if (!string.IsNullOrEmpty(extenionType))
  21. fileInfo = [.. fileInfo.Where(file => string.Equals(file.Extension.Replace(".", ""), extenionType.Replace(".", "")))];
  22. fileInfo.ForEach(t => tempFiles.Add(t.FullName));
  23. files = tempFiles;
  24. return true;
  25. }
  26. public static bool GetAllFiles(string folderPath, out List<FileInfo>? files, string? extenionType = null)
  27. {
  28. files = default;
  29. List<FileInfo> fileInfo;
  30. try
  31. {
  32. DirectoryInfo folder = new(folderPath);
  33. fileInfo = [.. folder.GetFiles()];
  34. }
  35. catch
  36. {
  37. return false;
  38. }
  39. files = fileInfo;
  40. return true;
  41. }
  42. }