所以我有一组文件名如下:
A-2.txt
B-1.TXT
c-3.txt
我正在尝试将它们重命名为:
1.txt -----> b-1.txt
2.txt -----> a-2.txt
3.txt -----> c-3.txt
但是,我无法弄清楚相应的正则表达式是什么,以及如何将其编码到PowerShell中。我看到大量的例子来删除空格或下划线,但没有任何东西要从字符串中删除。
答案 0 :(得分:-2)
试试这个(删除whatif)
Get-ChildItem "c:\temp" -file -Filter "*.txt" | where BaseName -Match ".-." | %{
$newname="{0}{1}" -f ($_.BaseName -split '-')[1], $_.Extension
Rename-Item $_.FullName $newname -WhatIf
}