DierctoryHelper.cs 835 B

12345678910111213141516171819202122232425262728293031323334
  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. }