本帖最后由 zaqmlp 于 2021-4-11 13:34 编辑
- <# :
- cls
- @echo off
- rem 存为ANSI编码的bat
- cd /d "%~dp0"
- powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::GetEncoding('GB2312')))) -Args '%~f0'"
- pause
- exit
- #>
- $self=get-item -liter $args[0];
- $path=$self.Directory.FullName;
- $enc=New-Object System.Text.UTF8Encoding $False;
- $files=@(dir -liter $path -recurse|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
- for($i=0;$i -lt $files.length;$i++){
- write-host $files[$i].FullName.substring($path.length);
- $arr=New-Object -TypeName System.Collections.ArrayList;
- $text=[IO.File]::ReadAllLines($files[$i].FullName,$enc);
- for($j=0;$j -lt $text.count;$j++){
- $global:n=1;
- $line=[regex]::replace($text[$j],'\t【',{
- param($m);
- $m.groups[0].value -replace '(?=【)',(($global:n).toString()+'.');
- $global:n++;
- });
- [void]$arr.add($line);
- }
- [IO.File]::WriteAllLines($files[$i].FullName,$arr,$enc);
- }
复制代码
|