- <# :
- cls&echo off&cd /d "%~dp0"
- path %SYSTEMROOT%\System32\WindowsPowerShell\v1.0;%path%
- set "tmpfile=%tmp%\t.t"
- setlocal enabledelayedexpansion
- >"%tmpfile%" echo;!cmdcmdline!
- endlocal
- powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0'|Out-String|Invoke-Expression"
- pause
- exit
- #>
- function exc($t){
- $tt=[int]('1'+$t);
- $n=-1;$nn='';
- $zrr=@(100,120,140,160,180);
- for($i=0;$i -lt $zrr.length;$i++){
- $m=[Math]::Abs($zrr[$i] -$tt);
- if($n -eq -1){
- $n =$m;$nn =$zrr[$i].toString();
- }else{
- if($m -lt $n){
- $n =$m;$nn =$zrr[$i].toString();
- }
- }
- }
- return $nn.Substring(1);
- }
-
- $text=[IO.File]::ReadAllText(($env:tmpfile), [Text.Encoding]::GetEncoding('GB2312'));
- $files=($text.trim() -replace '^.+?\.(cmd|bat)" ','').replace('"','') -split ' (?=[a-z]:)';
- $enc=New-Object System.Text.UTF8Encoding $False;
- for($i=0;$i -lt $files.length;$i++){
- write-host $files[$i];
- $arr=New-Object -TypeName System.Collections.ArrayList;$flag=@(1,'');
- $text=[IO.File]::ReadAllLines($files[$i], $enc);
- for($j=0;$j -lt $text.count;$j++){
- $line=$text[$j].trim();
- $m=[regex]::match($line, '(\d+:\d+:\d+,)(\d\d\d)( ?--> ?\d+:\d+:\d+,)(\d\d\d)');
- if($m.success){
- $ts='';
- $a=$m.groups[2].value.Substring(0,1)+(exc $m.groups[2].value.Substring(1,2));
- $b=$m.groups[4].value.Substring(0,1)+(exc $m.groups[4].value.Substring(1,2));
- if($flag[0] -eq 1){
- $ts=$m.groups[1].value+'000'+$m.groups[3].value+$b;
- }else{
- $ts=$m.groups[1].value+$flag[1]+$m.groups[3].value+$b;
- }
- $flag[1]=$b;$flag[0]++;
- [void]$arr.add($ts);
- }else{
- [void]$arr.add($text[$j]);
- }
- }
- [IO.File]::WriteAllLines($files[$i], ($arr -join "`r`n"), $enc);
- }
复制代码
|