test.bat
ansi编码,注意备份- #&cls&@cd /d "%~dp0" & powershell -c "Get-Content '%~0' | Out-String | Invoke-Expression" & pause&exit
- $shell = New-Object -ComObject 'Shell.Application'
- $folder = $shell.NameSpace($PWD.Path)
- #打开txt
- $txts = Get-Content 'a.txt'
- #找索引
- $i = $index1 = $index2 = $index3 = $index4 = 0
- while(!($index1 -and $index2 -and $index3 -and $index4)){
- if($folder.GetDetailsOf($null,$i) -eq '高度'){
- $index1 = $i
- }
- elseif($folder.GetDetailsOf($null,$i) -eq '宽度'){
- $index2 = $i
- }
- elseif($folder.GetDetailsOf($null,$i) -eq '帧高度'){
- $index3 = $i
- }
- elseif($folder.GetDetailsOf($null,$i) -eq '帧宽度'){
- $index4 = $i
- }
- ++$i
- }
- #重命名
- $folder.Items() | foreach {
- $__ = $_
- $t = $name = $null
- if($_.Name -match '^(.*?)\d+\.((png)|(jpg))$'){
- $t = '图片'; $name = $Matches[1]; $a = $index1; $b = $index2
- }
- elseif ($_.Name -match '^(.*?)\d+\.mp4$'){
- $t = '视频'; $name = $Matches[1]; $a = $index3; $b = $index4
- }
- if($t -ne $null -and $a -match '\d'){
- $b_find = $true
- $txts | foreach{
- if($b_find -and ($_ -match ('^{0}\d*,(.*?)$' -f $name)) ){
- $h = $folder.GetDetailsOf($__,$a) -replace '[^\d]',''
- $w = $folder.GetDetailsOf($__,$b) -replace '[^\d]',''
- $new_name = '{0}{1}__123--({2}x{3})——{4}' -f $t,$Matches[1],$h,$w,$__.Name
- $__.Name
- $new_name
- Rename-Item $__.Path $new_name
- $b_find = $false
- '---------------------------'
- }
- }
- }
- }
复制代码
|