| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace crusherScanner
- {
- internal static class SupportFunctions
- {
- /// <summary>
- /// Return a hash set of files in given folder.
- /// <code>
- /// GetFilesFromPath("c:\oreDefFiles\","ML??????*.csv");
- /// </code>
- /// </summary>
- /// <param name="Path">Path to search for files at.</param>
- /// <param name="Mask">Mask to check files against.</param>
- /// <returns>HashSet/<string/> of files in folder.</returns>
- public static HashSet<string> GetFilesFromPath(string Path,string Mask)
- {
- HashSet<string> files = new HashSet<string>();
- try
- {
- if (Directory.Exists(Path))
- {
- // Pattern match is for 'ML003092.csv' or 'ML003092_20220822.csv' = "ML??????*.csv"
- IEnumerable<string> 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;
- }
- }
- }
|