powershell重命名脚本
目的
把当前文件夹下的这些文件
重命名为
代码
Get-ChildItem -Path . -Filter "*.mkv" | ForEach-Object {
if ($_.Name[0] -ne "1") {
$fileName = $_.Name -replace "\.[^.]+$", ""
$pattern = '\[\d+\.?\d*\]'
if ($fileName -match $pattern) {
$match = $matches[0]
$newName = "0x" + $match.Trim('[', ']')
Write-Output $newName
Rename-Item -LiteralPath $_.FullName -NewName "$newName.mkv"
}
else {
Write-Output "No match found"
}
}
}