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. if (fileInfo is null || fileInfo.Count == 0)
  14. return true;
  15. if (!string.IsNullOrEmpty(extenionType))
  16. fileInfo = [.. fileInfo.Where(file => string.Equals(file.Extension.Replace(".", ""), extenionType.Replace(".", "")))];
  17. fileInfo.ForEach(t => tempFiles.Add(t.FullName));
  18. files = tempFiles;
  19. }
  20. catch
  21. {
  22. return false;
  23. }
  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. }