本帖最后由 WHY 于 2024-8-14 11:50 编辑
Test.ps1 | $srcFolder = 'E:\Test\'; | | | | $ext1 = @{'.jpg'=1; '.bmp'=1; '.png'=1; '.tif'=1; '.jpeg'=1} | | $name = @{'000'=1; '00.1'=1; '00.2'=1; '00.3'=1} | | $ext2 = @{'.mp4'=1; '.avi'=1; '.mov'=1; '.mkv'=1} | | $Hash = @{} | | | | Function Get-Size($sz) { | | If ($sz -ge 1GB) { | | return ($sz/1GB).ToString('0.00G'); | | } ElseIf ($sz -ge 1MB) { | | return ($sz/1MB).ToString('0.00M'); | | } Else { | | return ($sz/1KB).ToString('0.00K'); | | } | | } | | | | forEach ($f In (Get-ChildItem -Literal $srcFolder -Recurse -File -Filter *.*)) { | | $fd = $f.DirectoryName; | | If ($ext1.Contains($f.Extension) -and !$name.Contains($f.BaseName)) { | | If (!$Hash.Contains($fd)) { | | $Hash.Add($fd, @(1, 0, $f.Length)); | | } Else { | | $Hash[$fd][0] += 1; | | $Hash[$fd][2] += $f.Length; | | } | | } ElseIf ($ext2.Contains($f.Extension)) { | | If (!$Hash.Contains($fd)) { | | $Hash.Add($fd, @(0, 1, $f.Length)); | | } Else { | | $Hash[$fd][1] += 1; | | $Hash[$fd][2] += $f.Length; | | } | | } | | } | | | | $keys = $Hash.GetEnumerator().Name; | | [Array]::Sort($keys); | | | | for ($i=$keys.Count-1; $i -ge 0; $i--) { | | $k = $keys[$i]; | | $sufFix = '[' + $Hash[$k][0] + 'P' + $Hash[$k][1] + 'V-' + (Get-Size $Hash[$k][2]) + ']'; | | $sufFix = $sufFix -replace '(?-i)(?<=\D)0[PV]'; | | $newName = $k.Split('\')[-1] + $sufFix; | | Rename-Item -Literal $k -NewName $newName; | | } | | pauseCOPY |
|