简单重命名 - 从文件名中删除 (JOB_0000_)

Simple renaming - remove (JOB_0000_) from file name

我使用的软件会在特定文件夹中生成名称为 JOB_1_sample-file_20220211083122.txt 的输出文件。同时有数千个文件。

文本文件的开头是可变的(JOB_1、JOB_2、JOB_3 等)。

示例:JOB_2_sample-file_20220211083122.txt、JOB_34_sample-file_20220211083122.txt、JOB_1007_sample-file_20220211083122.txt.

我需要从文件中删除首字母,只留下 'sample' 向前。 最好使用 Powershell、CMD 或 javascript.

有这种可能吗?

使用Rename-Item with a delay-bind script block, combined with a -replace operation that uses a regex删除感兴趣的前缀:

$dir = '.' # specify target dir.
Get-ChildItem -LiteralPath $dir -Filter *.txt |
  Rename-Item -NewName { $_.Name -replace '^JOB_\d+_' } -WhatIf

注意:上面命令中的-WhatIf common parameter预览操作。一旦您确定该操作将执行您想要的操作,请删除 -WhatIf