- <# :
- cls&echo off&cd /d "%~dp0"
- powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText('%~f0',[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
- pause
- exit
- #>
- $newfolder="result";
- if(-not (test-path -literal $newfolder)){[void][IO.Directory]::CreateDirectory($newfolder)};
- $enc=[Text.Encoding]::GetEncoding('GB2312');
- $reg='('+[regex]::Escape('$CC32')+'.*?'+[regex]::Escape('$BB0')+')(\d+)('+[regex]::Escape('$HH')+')';
- $files=@(dir -literal "."|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
- for($i=0;$i -lt $files.length;$i++){
- write-host $files[$i].Name;
- $text=[IO.File]::ReadAllLines($files[$i].FullName, $enc);
- for($j=0;$j -lt $text.count;$j++){
- $text[$j]=[regex]::replace($text[$j], $reg, {
- param($m);
- $len=$m.groups[2].value.length;
- $value=([int]$m.groups[2].value - 600).toString().PadLeft($len, '0');
- $m.groups[1].value+$value+$m.groups[3].value;
- });
- }
- $newfile=$newfolder.trimend('\')+'\'+$files[$i].Name;
- [IO.File]::WriteAllLines($newfile, $text, $enc);
- }
复制代码
|