using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace crusherScanner { internal static class SupportFunctions { /// /// Return a hash set of files in given folder. /// /// GetFilesFromPath("c:\oreDefFiles\","ML??????*.csv"); /// /// /// Path to search for files at. /// Mask to check files against. /// HashSet/ of files in folder. public static HashSet GetFilesFromPath(string Path,string Mask) { HashSet files = new HashSet(); try { if (Directory.Exists(Path)) { // Pattern match is for 'ML003092.csv' or 'ML003092_20220822.csv' = "ML??????*.csv" IEnumerable jobFiles = Directory.EnumerateFiles(Path, Mask, SearchOption.TopDirectoryOnly); foreach (string jobFile in jobFiles) { files.Add(jobFile); } } else { Logging.Append(LogLevel.Debug, $"Unable to get files from non existant 'Path' {Path}."); } } catch (Exception ex) { Logging.Append(LogLevel.Error ,"An error occurred." + ex.Message); } // return an empty HashSet if no files found return files; } } }