PowerShell重命名文件名


Get-ChildItem -Path "G:\doc\目录" | ForEach-Object {
$extension = $_.Extension
$oldName = $_.Name
$newName = $oldName -replace "-","_"
Rename-Item -Path $_.FullName -NewName $newName
}

 


Get-ChildItem -Path "G:\doc\目录" | ForEach-Object {
$extension = $_.Extension
$oldName = $_.Name
$newName = $oldName.SubString(0,3)+"_"+$oldName.SubString(3,$oldName.length-3)
Rename-Item -Path $_.FullName -NewName $newName
}