// Example snippet structure of the parallel scanner logic
Parallel.ForEach(Directory.GetFiles(targetPath, ".", SearchOption.AllDirectories), file =>
{
using (var md5 = MD5.Create())
{
using (var stream = File.OpenRead(file))
{
var hash = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLowerInvariant();
// Register or track hash collisions for duplicate detection
}
}
});
The Problem
Sorting through massive directory structures manually is a time sink. I wanted a lightweight, native Windows utility built in C# that could handle background monitoring via FileSystemWatcher and instantly sweep directories for redundant files using parallel MD5 hashing.
Technical Implementation
Fast Duplicate Detection with Parallel Processing
To keep the scan times down on large drives, synchronous file reading doesn't cut it. By leveraging Parallel.ForEach combined with buffered stream reading, we can compute cryptographic hashes concurrently across multiple threads without choking system memory.Real-Time Directory Monitoring
Using FileSystemWatcher, the application hooks directly into target folders to catch file creations, renames, or movements on the fly, instantly applying sorting logic based on custom rules without requiring constant manual triggers.Generating Audit Reports
Once operations finish, the app structures the logs and writes out a clean, readable HTML summary report so you have a complete audit trail of what was sorted or cleaned.
Wrapping Up
If you're looking to grab the pre-compiled, standalone Windows executable version of this tool or want to check out how the UI and automated rules are packaged together, I've listed it over on Gumroad: bryjackson.gumroad.com/l/zxluba.
Happy coding! Let me know how you approach file automation in your own projects down in the comments.
Top comments (0)