You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用PowerShell将文件名中间的指定文本替换为递增序列

可用脚本

直接在存放目标文件的PowerShell窗口中运行以下代码即可:

# 初始化序号起始值,需要从其他数字开始修改这里即可
$index = 1
# 仅筛选符合AT-112-NewImage前缀的jpg文件,不影响其他已重命名的文件
Get-ChildItem -Filter "AT-112-NewImage-*.jpg" | ForEach-Object {
    # 替换文件名中的NewImage为D+当前序号
    $newFileName = $_.Name -replace "NewImage", "D$index"
    # 执行重命名
    Rename-Item -Path $_.FullName -NewName $newFileName
    # 序号自增1
    $index++
}

防错测试方法

如果担心改错,可以先运行带测试参数的版本,不会实际修改文件,只会输出预期的重命名结果:

$index = 1
Get-ChildItem -Filter "AT-112-NewImage-*.jpg" | ForEach-Object {
    $newFileName = $_.Name -replace "NewImage", "D$index"
    Rename-Item -Path $_.FullName -NewName $newFileName -WhatIf
    $index++
}

确认输出的新文件名符合要求后,删掉-WhatIf参数重新运行即可完成重命名。

内容的提问来源于stack exchange,提问作者IKnowNothing

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 11:54:01