Skip to content

Commit

Permalink
Filter files before processing in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
josepho0918 committed May 30, 2024
1 parent 3c79126 commit 609344d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ private static void ProcessDir(string directoryPath, HashSet<string> allowed_ext
{
Console.WriteLine($"Processing directory: {directoryPath}");

Parallel.ForEach(Directory.EnumerateFiles(directoryPath, "*", SearchOption.AllDirectories), file_path =>
var files = Directory.EnumerateFiles(directoryPath, "*", SearchOption.AllDirectories)
.AsParallel()
.Where(file_path => allowed_exts.Contains(Path.GetExtension(file_path).ToLower()));

Parallel.ForEach(files, file_path =>
{
string file_ext = Path.GetExtension(file_path).ToLower();
if (allowed_exts.Contains(file_ext))
{
RemoveTrailingBlanks(file_path);
sem.Wait();
Console.WriteLine(Path.GetRelativePath(directoryPath, file_path));
sem.Release();
}
RemoveTrailingBlanks(file_path);
sem.Wait();
Console.WriteLine(Path.GetRelativePath(directoryPath, file_path));
sem.Release();
});
}

Expand Down

0 comments on commit 609344d

Please sign in to comment.