Skip to content

Instantly share code, notes, and snippets.

@EricZimmerman
Created January 23, 2022 18:16
Show Gist options
  • Save EricZimmerman/82f8393d7a6e75c82108ff2ecaa83723 to your computer and use it in GitHub Desktop.
Save EricZimmerman/82f8393d7a6e75c82108ff2ecaa83723 to your computer and use it in GitHub Desktop.
.net 6 multipattern file find with ignore list and minimum size
static IEnumerable<string> FindFiles(string directory, IEnumerable<string> masks, HashSet<string> ignoreMasks, EnumerationOptions options,long minimumSize = 0)
{
foreach (var file in masks.AsParallel().SelectMany(searchPattern => Directory.EnumerateFiles(directory, searchPattern, options)))
{
var fi = new FileInfo(file);
if (fi.Length < minimumSize)
{
Log.Debug("Skipping {File} with size {Length:N0}",file,fi.Length);
continue;
}
var ext = Path.GetExtension(file);
if (ignoreMasks.Contains(ext))
{
Log.Debug("Skipping {File} since its extension ({Ext}) is in ignoreMasks",file,ext);
continue;
}
yield return file;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment