- <#*,:&cls
- @echo off
- pushd "%~dp0"
- powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~0\" -ReadCount 0 | Out-String ))) "
- popd
- pause
- exit /b
- #>
- # 我想让目录下的文件/文件夹(包含子文件夹)的全部文件和文件夹的名称全部改成 首字母大写单词-Capital Word
- Get-ChildItem -Path . -Filter * -Recurse | ForEach-Object -Begin {
- $re = [regex]'(?i)[a-z]+'
- $evaluator = [System.Text.RegularExpressions.MatchEvaluator] {
- param($m)
- $s = $m.Value.ToLower()
- return $s.Substring(0, 1).ToUpper() + $s.Substring(1)
- }
- } -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)`""
- }
- }
复制代码
|