- <# :
- cls
- @echo off
- set info=互助互利,支付宝扫码头像,感谢赞助
- rem 有问题,可加QQ956535081及时沟通
- title %info%
- set "rootpath=%~dp0"
- if "%rootpath:~-1%" equ "\" (set "rootpath=%rootpath:~,-1%")
- cd /d "%rootpath%"
- powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%rootpath%'"
- echo;%info%
- pause
- exit
- #>
-
- $name='';
- $number='';
-
- $web=New-Object System.Net.WebClient;
- $web.Encoding=[Text.Encoding]::UTF8;
- $html=$web.DownloadString('http://csstools.chinaz.com/tools/js/pinyin.js');
- $m=[regex]::match($html, 'var pydic ?= ?"([^\"]+)"');
- $pydic='';
- if($m.success){
- $pydic=$m.groups[1].value;
- }else{
- write-host 'dict failed';
- exit;
- };
-
- $date=get-date;
- $fs=@(dir -liter $args[0] -recurse|?{('.tif' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
- for($i=0;$i -lt $fs.length;$i++){
- $m=[regex]::match($fs[$i].BaseName,'^[^_-]+_[^_-]+_([^_-]+)-([^_-]+)-[^_-]+(?:_[^_-]+){3}_([^_-]+)$');
- if($m.Success){
- $oldname=$fs[$i].Name;
- $a='';
- $fname=$m.groups[1].value;
- for($j=0;$j -lt $fname.length;$j++){
- $n=$pydic.indexOf($fname[$j]);
- if($fname[$j] -match '[\u4e00-\u9fa5]'){
- if($n -ge 0){
- $t=$pydic.Substring($n+1,1);
- $t=($t -replace '[āáǎà]','a') -replace '[ōóǒò]','o';
- $t=($t -replace '[ēéěè]','e');
- $a+=$t;
- };
- }else{$a+=$fname[$j]};
- };
- $b=($m.groups[2].value -replace '^\D*','').PadLeft(3,'0');
- $c=$date.toString('yyyyMMdd');
- $d=$m.groups[3].value.Substring(0,1);
- $newname=$name+$a+'-'+$number+$b+'-'+$c+'-'+$d.toLower()+$fs[$i].Extension;
- if($newname -ne $oldname){
- write-host ($fs[$i].FullName+' --> '+$newname);
- mv -liter $fs[$i].FullName ($fs[$i].Directory.FullName+'\'+$newname);
- };
- };
- }
复制代码
|