namespace Universal;

public class DierctoryHelper
{

    public static bool GetAllFiles(string folderPath, out List<string>? files, string? extenionType = null)
    {
        files = default;
        List<FileInfo> fileInfo;
        List<string>? tempFiles = [];
        try
        {
            DirectoryInfo folder = new(folderPath);
            fileInfo = [.. folder.GetFiles()];

            if (fileInfo is null || fileInfo.Count == 0)
                return true;

            if (!string.IsNullOrEmpty(extenionType))
                fileInfo = [.. fileInfo.Where(file => string.Equals(file.Extension.Replace(".", ""), extenionType.Replace(".", "")))];

            fileInfo.ForEach(t => tempFiles.Add(t.FullName));
            files = tempFiles;

        }
        catch
        {
            return false;
        }
        return true;
    }

    public static bool GetAllFiles(string folderPath, out List<FileInfo>? files, string? extenionType = null)
    {
        files = default;
        List<FileInfo> fileInfo;
        try
        {
            DirectoryInfo folder = new(folderPath);
            fileInfo = [.. folder.GetFiles()];
        }
        catch
        {
            return false;
        }

        files = fileInfo;

        return true;
    }
}
