重复文件查找
免费在线按内容哈希扫描重复文件,输出清单,可一键把重复项移入回收站。
Windows去重清理
🪞Windows 本地工具 · 使用介绍
使用介绍
用途:找出文件夹里内容完全相同的重复文件(先按大小、再按 SHA-256 哈希确认),适合清理下载目录/备份目录。
使用步骤:
1.下载脚本,双击 `run.bat` 运行
2.输入要扫描的目录(可包含子文件夹)
3.扫描完成后列出重复项,确认 y 后把重复文件移入回收站(每组保留最早的一个)
安全说明:重复项默认只进回收站,可随时还原;不删除唯一文件。大目录扫描会较慢(需计算哈希)。
脚本为纯文本(PowerShell),可先用记事本打开查看源码再运行;仅在本机执行,不会上传任何数据。 首次运行如被系统拦截,右键脚本 → 属性 → 解除锁定,或用启动器(已带 ExecutionPolicy Bypass)运行。
脚本源码预览(可复制)
# ==================================================
# 重复文件查找(NMHUB 牛马工具)
# 先按大小分组,再按内容哈希确认,输出重复清单
# 安全:默认只输出清单;可选把重复项移入回收站(保留一份)
# ==================================================
$ErrorActionPreference = "Continue"
Write-Host ""
Write-Host "========== 重复文件查找 ==========" -ForegroundColor Cyan
$dir = Read-Host "请输入要扫描的目录(回车 = 当前目录)"
if (-not $dir) { $dir = (Get-Location).Path }
if (-not (Test-Path -LiteralPath $dir)) {
Write-Host "路径不存在。" -ForegroundColor Red
Read-Host "按回车退出"; exit 1
}
Write-Host "正在扫描文件…" -ForegroundColor Green
$files = Get-ChildItem -LiteralPath $dir -File -Recurse -ErrorAction SilentlyContinue
Write-Host "共 $($files.Count) 个文件,正在计算哈希…"
$groups = $files | Group-Object Length | Where-Object { $_.Count -gt 1 }
$dupes = @()
foreach ($g in $groups) {
$hashMap = @{}
foreach ($f in $g.Group) {
try {
$hash = (Get-FileHash -LiteralPath $f.FullName -Algorithm SHA256 -ErrorAction Stop).Hash
if ($hashMap.ContainsKey($hash)) {
$dupes += @{ Keep = $hashMap[$hash]; Dupe = $f.FullName; Hash = $hash }
} else {
$hashMap[$hash] = $f.FullName
}
} catch { }
}
}
Write-Host ""
if ($dupes.Count -eq 0) {
Write-Host "未发现重复文件(内容完全相同)。" -ForegroundColor Green
Read-Host "按回车退出"; exit
}
Write-Host "发现 $($dupes.Count) 个重复文件(每组保留最早的一个):" -ForegroundColor Yellow
foreach ($d in $dupes) { Write-Host " 重复: $($d.Dupe)" }
$confirm = Read-Host "是否把重复项移入回收站(保留每组一份)?(y/n)"
if ($confirm -ne "y" -and $confirm -ne "Y") {
Write-Host "未做任何改动。清单已在上方。" -ForegroundColor Yellow
Read-Host "按回车退出"; exit
}
Add-Type -AssemblyName Microsoft.VisualBasic
$moved = 0
foreach ($d in $dupes) {
try {
[Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile($d.Dupe, "OnlyErrorDialogs", "SendToRecycleBin")
$moved++
} catch { Write-Host "失败: $($d.Dupe)" -ForegroundColor Red }
}
Write-Host "完成,移入回收站 $moved 个。" -ForegroundColor Green
Read-Host "按回车退出"