Skip to content

Repository files navigation

DuplicateFileManager

A PowerShell binary module for managing duplicate files. Provides cmdlets to detect and remove duplicate files within a directory, and find files with duplicate names across directories.

Installation

From Build Output

Import-Module "path/to/DuplicateFileManager.dll"

Install to PowerShell Modules Directory

# Build the module
dotnet build src/DuplicateFileManager/DuplicateFileManager.csproj -c Release

# Copy to PowerShell modules directory
$modulePath = "$HOME/Documents/PowerShell/Modules/DuplicateFileManager"
New-Item -ItemType Directory -Path $modulePath -Force
Copy-Item src/DuplicateFileManager/bin/Release/net8.0/DuplicateFileManager.dll $modulePath/
Copy-Item build/DuplicateFileManager.psd1 $modulePath/

# Import
Import-Module DuplicateFileManager

Command Reference

Remove-DuplicateFile

Detects and removes duplicate files within a single directory using SHA-256 hash comparison.

Syntax

Remove-DuplicateFile [-Path] <string> [-TempDirectory <string>] [-Permanent]
                     [-PartialHashBytes <int>] [-NoColor] [-WhatIf] [-Confirm]

Parameters

Parameter Type Required Default Description
-Path string Yes - Target directory to scan for duplicates
-TempDirectory string No System Temp Directory to move duplicate files to
-Permanent switch No false Delete files immediately instead of moving
-PartialHashBytes int No 65536 Number of bytes for partial hash calculation
-NoColor switch No false Suppress colored output
-WhatIf switch No - Show what would happen without making changes
-Confirm switch No - Prompt for confirmation before each action

Algorithm

  1. Enumerate files in directory (non-recursive)
  2. Group by file size (eliminate unique sizes)
  3. Calculate partial hash (first N bytes)
  4. Group by partial hash (eliminate unique hashes)
  5. Calculate full SHA-256 hash
  6. Group by full hash
  7. Within each group, keep oldest file (by LastWriteTime), mark others as duplicates

Examples

# Dry-run to see what would be removed
Remove-DuplicateFile -Path "C:\Photos" -WhatIf

# Move duplicates to specified directory
Remove-DuplicateFile -Path "C:\Photos" -TempDirectory "C:\Temp\Duplicates"

# Permanently delete duplicates with confirmation
Remove-DuplicateFile -Path "C:\Photos" -Permanent -Confirm

# Suppress colored output
Remove-DuplicateFile -Path "C:\Photos" -NoColor

Find-DuplicateFileName

Finds files with matching names between two directories.

Syntax

Find-DuplicateFileName [-ReferencePath] <string> [-DifferencePath] <string>
                       [-CaseSensitive] [-SingleLine] [-NoColor]

Parameters

Parameter Type Required Default Description
-ReferencePath string Yes - Source directory for comparison
-DifferencePath string Yes - Target directory to compare against
-CaseSensitive switch No false Enable case-sensitive filename comparison
-SingleLine switch No false Compact single-line output format
-NoColor switch No false Suppress colored output

Output

Returns FileNameMatch objects with the following properties:

Property Type Description
FileName string The matching file name
ReferenceFullPath string Full path in reference directory
DifferenceFullPath string Full path in difference directory
ReferenceLastWriteTime DateTime Last modified time in reference
DifferenceLastWriteTime DateTime Last modified time in difference
ReferenceSize long File size in reference directory
DifferenceSize long File size in difference directory

Examples

# Find duplicate file names
Find-DuplicateFileName -ReferencePath "C:\Original" -DifferencePath "C:\Backup"

# Case-sensitive comparison
Find-DuplicateFileName -ReferencePath "C:\Dir1" -DifferencePath "C:\Dir2" -CaseSensitive

# Compact single-line output
Find-DuplicateFileName -ReferencePath "C:\Dir1" -DifferencePath "C:\Dir2" -SingleLine

# Export results to CSV
Find-DuplicateFileName -ReferencePath "C:\Dir1" -DifferencePath "C:\Dir2" |
    Export-Csv -Path "duplicates.csv" -NoTypeInformation

Build

Prerequisites

  • .NET 8.0 SDK or later
  • PowerShell 7.0 or later

Build Commands

# Restore and build
dotnet build src/DuplicateFileManager/DuplicateFileManager.csproj

# Build release
dotnet build src/DuplicateFileManager/DuplicateFileManager.csproj -c Release

About

A PowerShell binary module for managing duplicate files. Provides cmdlets to detect and remove duplicate files within a directory, and find files with duplicate names across directories.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages