bat存为ANSI/GB2312编码- <# :
- cls&echo off&cd /d "%~dp0"&mode con lines=5000
- set "current=%cd%"
- powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText(\"%~f0\",[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
- pause
- exit
- #>
- $current=get-item -literal $env:current;
- $files=@(dir -literal $current.FullName -recurse|?{($_.Extension -eq '.srt') -and ($_ -is [System.IO.FileInfo])});
-
- $enc=New-Object System.Text.UTF8Encoding $False;
- [System.Collections.ArrayList]$filelist=@();
- for($i=0;$i -lt $files.length;$i++){
- $text=[IO.File]::ReadAllText($files[$i].FullName, $enc);
- $m=[regex]::match($text, '(?i)\{\\pos\(\d+ ?, ?\d+\)\}');
- if($m.Success){
- [void]$filelist.add($files[$i]);
- write-host ($m.groups[0].value+' '+$files[$i].FullName.Substring($current.FullName.length));
- }
- }
-
- if($filelist.Count -ge 1){
- write-host '1、修改位置标签';
- write-host '2、清除位置标签';
-
- $choice1='';
- while($choice1 -notmatch '^(1|2)$'){
- $choice1=read-host '输入数字序号并回车';
- }
-
- $pos='';
- if($choice1 -eq '1'){
- $x_value=read-host '输入x坐标并回车';
- $y_value=read-host '输入y坐标并回车';
- if(($x_value -notmatch '^\d+$') -or ($y_value -notmatch '^\d+$')){
- write-host '输入有误';exit;
- }
- $pos='{\pos('+$x_value+','+$y_value+')}';
- }
- clear-host;
- for($i=0;$i -lt $filelist.Count;$i++){
- write-host $filelist[$i].FullName.Substring($current.FullName.length);
- $text=[IO.File]::ReadAllText($filelist[$i].FullName, $enc);
- $text=$text -replace '\{\\pos\(\d+ ?, ?\d+\)\}', $pos;
- [IO.File]::WriteAllText($filelist[$i].FullName, $text, $enc);
- }
- }else{
- $pos='';
- $x_value=read-host '输入x坐标并回车';
- $y_value=read-host '输入y坐标并回车';
- if(($x_value -notmatch '^\d+$') -or ($y_value -notmatch '^\d+$')){
- write-host '输入有误';exit;
- }
- $pos='{\pos('+$x_value+','+$y_value+')}';
-
- for($i=0;$i -lt $files.length;$i++){
- write-host $files[$i].FullName.Substring($current.FullName.length);
- [System.Collections.ArrayList]$newtext=@();
- $oldtext=[IO.File]::ReadAllText($files[$i].FullName, $enc);
- $arr=$oldtext.trim() -split '[\r\n]{3,}';
- for($j=0;$j -lt $arr.length;$j++){
- $brr=$arr[$j] -split '[\r\n]+';
- if(-not [string]::IsNullOrEmpty($brr[2])){
- if(($brr[2] -notmatch '\{\\an\d+\}')){
- $brr[2]=$pos+$brr[2];
- }
- }
- $line=$brr -join "`r`n";
- [void]$newtext.add($line);
- }
- [IO.File]::WriteAllText($files[$i].FullName, $($newtext -join "`r`n`r`n"), $enc);
- }
- }
复制代码
|