cd c:\temp
'X_01_00007_11_1.bat','X_1_07_06_02.bat','X_2_22_14_01_02.bat','X_000_0_07_06_02.bat'|% {
New-Item $_ -Force}
Get-ChildItem -Path C:\Temp -File |ForEach-Object {
$oldname=$_.Name
$newname = $oldname -replace '_0+(?=\d)', '_'
#or
#$newname = $oldname -replace '_0+(\d)', '_$1'
Rename-Item $oldname -NewName $newname
}
目录: C: \ temp
Режим LastWriteTime Длина Имя
---- ------------- ------ ----
-a ---- 2018/5/7 20:55 0 X_01_00007_11_1.bat
-a ---- 2018/5/7 20:55 0 X_1_07_06_02.bat
-a ---- 2018/5/7 20:55 0 X_2_22_14_01_02.bat
-a ---- 2018/5/7 20:55 0 X_000_0_07_06_02.bat
PS C: \ temp> dir
目录: C: \ temp
Режим LastWriteTime Длина Имя
---- ------------- ------ ----
-a ---- 2018/5/7 20:55 0 X_0_0_7_6_2.bat
-a ---- 2018/5/7 20:55 0 X_1_7_11_1.bat
-a ---- 2018/5/7 20:55 0 X_1_7_6_2.bat
-a ---- 2018/5/7 20:55 0 X_2_22_14_1_2.bat