效果:去除文件夹和子文件内的所有重复文件,只保留第一个。
WIN8 WIN10 按 [SHIFT]后 会在文件夹点右键后的菜单中底部显示。WIN7 可能会直接显示,WIN7 因该不支持[SHIFT]功能。
过滤方法是 哈希值 验证。 N 种方法中的 一种:保存为 DelRepeatFiles.ps1 右键运行。- $Code = @'
- @echo off & cd/d "%~dp0"
- set "Folder=%~1"
-
- Powershell -executionpolicy remotesigned ^
- $TMP = @{};^
- ls '%Folder%' -filter * -exclude "$PSCommandPath" -rec ^|^
- Where {$_.Directory} ^| Sort -desc ^|^
- Foreach {^
- $hash = ( get-filehash $_.fullname -algorithm sha256 ).hash;^
- if ( $TMP.ContainsKey( $hash ) ) {^
- del $_.fullname -verb;^
- } else { $TMP.Add( $hash,$_ ) };^
- };
- CMD /c pause;
- '@
-
- $Execution = @'
- Copy "$env:temp\清理文件夹内重复文件.CMD" -dest "$env:windir" -force;
- $reg = "Registry::HKCR\Folder\shell";
- New-Item "$reg\DelRepeatFile" -force -verb;
- New-ItemProperty "$reg\DelRepeatFile" -Name 'Extended' -force -verb;
- New-ItemProperty "$reg\DelRepeatFile" -Name 'MUIVerb' -Value '删除重复的多余文件' -Force -verb;
- New-ItemProperty "$reg\DelRepeatFile" -Name 'Position' -Value 'Bottom' -Force -verb;
- New-ItemProperty "$reg\DelRepeatFile" -Name 'Icon' -Value 'SHELL32.dll,171' -Force -verb;
-
- New-Item "$reg\DelRepeatFile\command" -force -verb;
- Set-ItemProperty "$reg\DelRepeatFile\command" -Name '(default)' -type 'ExpandString' -Value "`"%Windir%\清理文件夹内重复文件.cmd`" `"%1`"" -force -verb;
-
- $file = Get-Item "$env:Windir\清理文件夹内重复文件.CMD";
- $file.Attributes = 'ReadOnly','System','Hidden','Archive';
- CMD /c pause;
- '@
-
- Set-content "$env:temp\清理文件夹内重复文件.CMD" -Value $Code -enc Default -force;
- Set-content "$env:temp\Reg.ps1" -Value $Execution -enc Default -force;
-
- Start-Process Powershell.exe "-NoProfile -Execution RemoteSigned -File `"$env:temp\Reg.ps1`"" -verb runas;
- CMD /c pause;
- Remove-Item "$env:temp\清理文件夹内重复文件.CMD" -Force;
- Remove-Item "$env:temp\Reg.ps1" -Force;
复制代码 =============Enjoy==================== |