批量改文件名
免费在线一键给整批文件加前缀/后缀、替换文字或序号重命名,办公文件整理神器。
Windows改名批量
🏷️Windows 本地工具 · 使用介绍
热门使用介绍
用途:批量重命名文件夹里的所有文件,支持三种模式:
1.添加前缀/后缀:如统一加 `2026_` 前缀或 `_最终版` 后缀
2.替换文本:把文件名中的指定文字批量替换/删除
3.序号重命名:生成 `file_001.jpg`、`file_002.jpg`… 式的序号文件名
使用步骤:
1.下载脚本:点击下方「下载脚本 (.ps1)」;或下载「双击启动器 (.bat)」放到脚本同目录
2.把脚本放到(或指向)要处理的文件夹
3.双击 `run.bat` 运行(或右键 tool.ps1 → 使用 PowerShell 运行)
4.按提示输入文件夹路径,选择模式并填写参数
5.查看结果,回车退出
安全说明:脚本只做重命名,不删除任何文件;建议先在少量文件上试运行。脚本为纯文本,可打开任意编辑器查看源码。
脚本为纯文本(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
}
$files = Get-ChildItem -LiteralPath $dir -File
if ($files.Count -eq 0) {
Write-Host "该目录下没有文件。" -ForegroundColor Yellow
Read-Host "按回车退出"; exit
}
Write-Host "该目录共有 $($files.Count) 个文件。" -ForegroundColor Green
Write-Host ""
Write-Host "请选择操作:"
Write-Host " 1) 添加前缀/后缀"
Write-Host " 2) 替换文本"
Write-Host " 3) 序号重命名(file_001.jpg ...)"
$mode = Read-Host "输入 1/2/3"
$renamed = 0
switch ($mode) {
"1" {
$prefix = Read-Host "前缀(回车 = 无)"
$suffix = Read-Host "后缀,不含扩展名(回车 = 无)"
foreach ($f in $files) {
$newName = "$prefix$($f.BaseName)$suffix$($f.Extension)"
if ($newName -ne $f.Name) {
Rename-Item -LiteralPath $f.FullName -NewName $newName -ErrorAction SilentlyContinue
if ($?) { $renamed++ } else { Write-Host "失败: $($f.Name)" -ForegroundColor Red }
}
}
}
"2" {
$oldText = Read-Host "要被替换的文字"
$newText = Read-Host "替换为(回车 = 删除该文字)"
if (-not $oldText) { Write-Host "替换文字不能为空。" -ForegroundColor Red; Read-Host "按回车退出"; exit }
foreach ($f in $files) {
$newBase = $f.BaseName.Replace($oldText, $newText)
if ($newBase -ne $f.BaseName) {
Rename-Item -LiteralPath $f.FullName -NewName "$newBase$($f.Extension)" -ErrorAction SilentlyContinue
if ($?) { $renamed++ } else { Write-Host "失败: $($f.Name)" -ForegroundColor Red }
}
}
}
"3" {
$pre = Read-Host "文件名前缀(如 file_,回车 = 无)"
$start = Read-Host "起始序号(默认 1)"; if (-not $start) { $start = 1 }
$pad = Read-Host "序号位数(默认 3,如 001)"; if (-not $pad) { $pad = 3 }
$i = [int]$start
foreach ($f in $files) {
$num = $i.ToString("D$pad")
$newName = "$pre$num$($f.Extension)"
Rename-Item -LiteralPath $f.FullName -NewName $newName -ErrorAction SilentlyContinue
if ($?) { $renamed++ } else { Write-Host "失败: $($f.Name)" -ForegroundColor Red }
$i++
}
}
default { Write-Host "输入无效。" -ForegroundColor Red }
}
Write-Host ""
Write-Host "完成,共重命名 $renamed 个文件。" -ForegroundColor Green
Read-Host "按回车退出"