回复 3# itunesis - <#*,:&cls
- @echo off
- pushd "%~dp0"
- powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~0\" -ReadCount 0 | Out-String ))) "
- popd
- pause
- exit /b
- #>
- # 我想让目录下的文件/文件夹(包含子文件夹)的全部文件和文件夹的名称 数字之间的.号给替换成-号
- Get-ChildItem -Path . -Filter * -Recurse | ForEach-Object -Begin {
- $re = [regex]'(?<=\d)\.+(?=\d)'
- } -Process {
- $baseName = $_.PSChildName.Substring(0, $_.PSChildName.Length - $_.Extension.Length)
- $newName = $re.Replace($baseName, '-')
- if ($newName -cne $_.BaseName) {
- # Rename-Item -Path ($_.FullName -replace '[\[\]]', '`$&') -NewName $newName -Verbose
- # $_.MoveTo($newName)
- cmd.exe /c "ren `"$($_.FullName)`" `"$newName$($_.Extension)`""
- }
- }
复制代码
|