按清单批量改名
免费在线用 Excel/CSV 清单(旧名→新名)批量改名,带冲突检测与执行前预览。
Windows改名CSV
📋Windows 本地工具 · 使用介绍
使用介绍
用途:当重命名规则复杂、需要精确控制时,先在 Excel 里准备好「旧文件名,新文件名」两列清单,脚本按清单逐条改名。
准备清单:
1.新建 CSV 文件(Excel 另存为「CSV UTF-8」),每行两列:
`旧文件名.txt,新文件名.txt`
2.保存后用记事本确认编码为 UTF-8
使用步骤:
1.下载脚本并双击 `run.bat` 运行
2.输入 CSV 清单路径与文件所在目录
3.脚本会先列出将要执行的改名计划(跳过:旧文件不存在、新名已存在)
4.确认 y 后执行
安全说明:执行前必看预览清单;同名冲突自动跳过,绝不覆盖已有文件。
脚本为纯文本(PowerShell),可先用记事本打开查看源码再运行;仅在本机执行,不会上传任何数据。 首次运行如被系统拦截,右键脚本 → 属性 → 解除锁定,或用启动器(已带 ExecutionPolicy Bypass)运行。
脚本源码预览(可复制)
# ==================================================
# 按清单批量改名(NMHUB 牛马工具)
# 准备一个 CSV 文件(UTF-8),每行两列:旧文件名,新文件名
# 例如:旧名.txt,新名.txt
# 安全:改名前列出计划,确认后才执行;自动跳过冲突
# ==================================================
$ErrorActionPreference = "Continue"
Write-Host ""
Write-Host "========== 按清单批量改名 ==========" -ForegroundColor Cyan
$csvPath = Read-Host "请输入 CSV 清单路径(UTF-8 编码,每行: 旧名,新名)"
if (-not (Test-Path -LiteralPath $csvPath)) {
Write-Host "清单文件不存在。" -ForegroundColor Red
Read-Host "按回车退出"; exit 1
}
$dir = Read-Host "请输入文件所在目录(回车 = 清单所在目录)"
if (-not $dir) { $dir = Split-Path -Parent $csvPath }
$plan = @()
$invalid = 0
foreach ($line in Get-Content -LiteralPath $csvPath -Encoding UTF8) {
if (-not $line.Trim()) { continue }
$parts = $line -split ",", 2
if ($parts.Count -lt 2) { $invalid++; continue }
$oldName = $parts[0].Trim()
$newName = $parts[1].Trim()
if (-not $oldName -or -not $newName) { $invalid++; continue }
$oldPath = Join-Path $dir $oldName
$newPath = Join-Path $dir $newName
if (Test-Path -LiteralPath $oldPath) {
if (Test-Path -LiteralPath $newPath) {
Write-Host "跳过(新名已存在): $oldName -> $newName" -ForegroundColor Yellow
} else {
$plan += @{ Old = $oldPath; New = $newPath; Name = $oldName }
}
} else {
Write-Host "跳过(旧文件不存在): $oldName" -ForegroundColor Yellow
}
}
Write-Host ""
Write-Host "共 $($plan.Count) 条将执行:"
foreach ($p in $plan) { Write-Host " $($p.Name)" }
if ($invalid -gt 0) { Write-Host "另有 $invalid 行格式无效被跳过。" -ForegroundColor Yellow }
$confirm = Read-Host "确认执行?(y/n)"
if ($confirm -ne "y" -and $confirm -ne "Y") {
Write-Host "已取消。" -ForegroundColor Yellow
Read-Host "按回车退出"; exit
}
$done = 0
foreach ($p in $plan) {
Rename-Item -LiteralPath $p.Old -NewName (Split-Path -Leaf $p.New) -ErrorAction SilentlyContinue
if ($?) { $done++ } else { Write-Host "失败: $($p.Name)" -ForegroundColor Red }
}
Write-Host ""
Write-Host "完成,成功 $done / $($plan.Count)。" -ForegroundColor Green
Read-Host "按回车退出"