Skip to content
This repository has been archived by the owner on Jun 13, 2018. It is now read-only.
ILya-Lev edited this page Jun 13, 2018 · 2 revisions

This app removes file duplicates in specified folder via storing them into backup folder (3rd input parameter).

How to use.

Run it from terminal. Examples:

  1. UniqueFiles.ConsoleApp.exe h --- show user manual
  2. UniqueFiles.ConsoleApp.exe p D:\source D:\backup --- clean up source and store duplicates in backup; preserve empty folders inside source
  3. UniqueFiles.ConsoleApp.exe e D:\source --- clean up source, store duplicates in source\bkp and erase empty folders inside source

Applications in the solution

ConsoleApp is .NET Core application - publish it as standalone if you do not have .NET Core on target machine. Output should be of size approximately 80 MB.

ConsoleFrameworkApp is .NET Framework application - just build and copy bin\Debug or bin\Release content onto target machine.

Design notes

Top level abstraction is a ITransaction interface. It's a Command which sets up all components and triggers source folder cleaning process. It's useful as initially it was not decided whether empty sub folders should be removed or not.

Each ITransaction descendant instance delegates a part of whole work to BackupDirectoryManager and DuplicateCleaner entities. The first one creates/removes (if there are no duplicates) backup folder. The later one goes through all sub-folders of source folder and triggers each file processing.

IUniqueFilesRegistry and IBackedUpFilesRegistry are introduced to help us decide what should be done with a file. The first one is simply a wrapped HashSet (which allows to check if the file is unique). The later is a Dictionary with Task based mechanism of files moving from one location to another. It also provides primitive synchronization mechanism for entities which delete empty folders (all files should be moved before we try to delete a folder).

DirectoryProvider filters out backup folder to avoid redundant work and infinite loops (when it's a sub-folder with respect to a root one).

Clone this wiki locally