1

I have a few hundred thousand files to go through which are all sitting in one folder. I need to find and delete the duplicates. The problem is, the duplicate files only have similar names, not exactly the same. The other parts are different. Is it possible to use powershell-ISE to find files based on similar names, then delete the duplicate files that have a name length shorter than 7 characters?

I am very new to Powershell, so any answers will need to be explained. :)

Thank you.

Manetheren
  • 11
  • 2
  • How would I go about setting a date range for it to delete the files? I want to delete the files in blocks of one month. – Manetheren Sep 06 '16 at 21:32
  • So, I figured it out with some assistance from a friend. It won't let me post the whole script it one part, so here's three comments with the script. $From = "08/01/2016" $Until = "08/03/2016" $Files = Get-ChildItem "\\NetworkDrive\Duplicates" -Filter "*.tif" | Where-Object {$_.LastWriteTime -le $Until -and $_.LastWriteTime -ge $From} foreach ($File in $Files) – Manetheren Sep 07 '16 at 01:25
  • { $ExFiles = Get-ChildItem "\\NetworkDrive\Duplicates" -Filter "*.tif" | Where-Object {$_.LastWriteTime -le $Until -and $_.LastWriteTime -ge $From} foreach ($ExFile in $ExFiles) { if ($File.Name -ne $ExFile.Name) { if ("*" + $File.BaseName + "*" -like "*" + $ExFile.BaseName + "*") # if ("*" + $ExFile.BaseName + "*" -like "*" + $File.BaseName + "*") – Manetheren Sep 07 '16 at 01:25
  • { $File.Name + " - " + $ExFile.Name $Path = "\\NetworkDrive\Duplicates\" + $ExFile.Name $Dest = "\\NetworkDrive\Duplicates\Temp" Move-Item $Path -Destination $Dest } } } } – Manetheren Sep 07 '16 at 01:28
  • It's OK to answer your own question. You should remove the comments and post that code as an answer. Hit CTL K to enter code. Indent 4 spaces for each additional line. Check the preview panel underneath to make sure format is correct before submitting as this may be useful for others. Glad you got it working. – Randy Schuman Sep 07 '16 at 01:57

0 Answers0