用于重命名文件的Powershell脚本

use*_*651 4 powershell powershell-3.0

我有一堆文件,其名称以数字开头,可能在两个数字之一后包含空格和短划线,然后有时(有时不会)在我想要保留的名称的第一个字母字符之前有一个空格,即:

2-01 Dazed And Confused.txt(我想将其重命名为Dazed And Confused.txt)

要么

02 - Uncle Salty.txt(我想将其重命名为Uncle Salty.txt)

要么

02-The Night Before.txt(我想重命名为The Night Before.txt)

Emp*_*LII 6

Move-ItemRename-Item的cmdlet可以直接从管道接受源和使用脚本块提供了一个新的名字:

dir | Move-Item -Destination { $_.Name -replace '^([0-9\-\s]*)' }
Run Code Online (Sandbox Code Playgroud)

要么

dir | Rename-Item -NewName { $_.Name -replace '^([0-9\-\s]*)' }
Run Code Online (Sandbox Code Playgroud)