Skip to content

Instantly share code, notes, and snippets.

@matchy233
Created April 22, 2023 12:52
Show Gist options
  • Save matchy233/376cb201b95d9d458746750a0249befa to your computer and use it in GitHub Desktop.
Save matchy233/376cb201b95d9d458746750a0249befa to your computer and use it in GitHub Desktop.
Remove duplicated downloaded files
Function Remove-DupDownloads {
param (
[string]$SearchPath = ".",
[switch]$Recurse = $false
)
$FilePattern = '.*\([1-9][0-9]*\).*'
$GCIParams = @{
'Path' = $SearchPath
'File' = $true
}
if ($Recurse) {
$GCIParams.Add('Recurse', $true)
}
$RecycleBin = (New-Object -ComObject Shell.Application).Namespace(0xA)
Get-ChildItem @GCIParams |
Where-Object { $_.Name -match $FilePattern } |
ForEach-Object {
Write-Host "Moving file to Recycle Bin: $($_.FullName)"
$RecycleBin.MoveHere($_.FullName)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment