PowerShell批量改名

$files = Get-Location | Get-ChildItem

$current = Get-Location

Write-Output $current.Path

for ($i = 0; $i -lt $files.Length; $i++) {

    $file = $files[$i]

    if ($file.FullName.EndsWith(".png")) {

        Write-Output "-------------------"  

        $array = $file.Name.Replace("等级勋章/", "").Split("@")

        $b = $array[1].Replace("2x(", "").Replace(").png", "")

        $num = 0

        if (-Not($b.Equals("2x.png"))) {

            $num = $b -as [int]

        }

        $level = ($array[0].Split("-")[0] -as [int]) + $num

        $resultName =  $file.Directory.FullName+"\"+("level_"+$level+".png")

        Rename-Item -Path $file.FullName -NewName $resultName

        Write-Output ("Rename "+$file.FullName+" to " +$resultName)

        # Write-Output $array[0]

        # Write-Output $num

    }

}

#code

作者:徐影魔

出处:https://www.cnblogs.com/xunevermore/p/17794872.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   徐影魔  阅读(22)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
more_horiz
keyboard_arrow_up light_mode palette
选择主题
点击右上角即可分享
微信分享提示