Leak Society - The Home Of Nulled Resources.
Forum Beta v1 Now Live!
Need tool advice
Thead Owner : HailBoy23, Category : Lounge, 1 Comment, 195 Read
Viewers: 1 Guest(s)
Member
***
217
Messages
15
Threads
0
Rep
4 Years of Service
06-17-2021, 09:54 AM
#1
Hi everyone,

Is there any opensource or free tool to compare & delete duplicate files using hash values, I use windows ? 

Thanks in advance
Member
***
92
Messages
6
Threads
0
Rep
4 Years of Service
06-23-2021, 12:39 AM
#2
Windows 7 so that means you have PowerShell. You don't need some fancy tool or anything PowerShell should be enough.

Reference:

https://docs.microsoft.com/en-us/powersh...rshell-7.1
https://www.tutorialspoint.com/powershel...ng.htmNote: Always make sure you know what the source code is doing before running anything.

Code:
Write-Host "Write a path: "
$UserInput=Read-Host

#Get-FileHash cmdlet to get the hashes

$files = Get-ChildItem -Path $UserInput -Recurse | Where-Object -FilterScript { !$_.PSIsContainer }
$hashes = $files | ForEach-Object -Process {Get-FileHash -Path $_.FullName -Algorithm SHA256}

$duplicates = $hashes | Group-Object -Property Hash | Where-Object -FilterScript {$_.Count -gt 1}

foreach($duplicate in $duplicates)
{
    Write-Host -Object "These files share hash : $($duplicate.Group.Path -join ', ')"

    # delete all duplicates except the first
     foreach($duplicatePath in ($duplicate.Group.Path | Select-Object -Skip 1))
    # {
         Remove-Item -Path $duplicatePath -Force -WhatIf
    # }
}























 


Forum Jump: