Created
April 22, 2023 12:52
-
-
Save matchy233/376cb201b95d9d458746750a0249befa to your computer and use it in GitHub Desktop.
Remove duplicated downloaded files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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