Created
January 23, 2022 18:16
-
-
Save EricZimmerman/82f8393d7a6e75c82108ff2ecaa83723 to your computer and use it in GitHub Desktop.
.net 6 multipattern file find with ignore list and minimum size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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