本帖最后由 flashercs 于 2020-1-31 23:21 编辑
- <#*,:&cls
- @echo off
- pushd "%~dp0"
- powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~0\" -ReadCount 0 | Out-String ))) "
- popd
- pause
- exit /b
- #>
- # 我想让目录下的文件/文件夹(包含子文件夹)的全部文件和文件夹的名称全部改成大写,但是在这个括号 [abcd] 内的字母不作改动
- Get-ChildItem -Path . -Filter * -Recurse | ForEach-Object -Begin {
- $re = [regex]'(\[[^\[\]]+\])|[a-z]+'
- $evaluator = [System.Text.RegularExpressions.MatchEvaluator] {
- param($m)
- if ($m.Groups[1].Success) {
- return $m.Value
- } else {
- return $m.Value.ToUpper()
- }
- }
- } -Process {
- $newName = $re.Replace($_.BaseName, $evaluator)
- if ($newName -cne $_.BaseName) {
- # Rename-Item -Path ($_.FullName -replace '[\[\]]', '`$&') -NewName $newName
- # $_.MoveTo($newName)
- cmd.exe /c "ren `"$($_.FullName)`" `"$newName$($_.Extension)`""
- }
- }
复制代码
|