回复 9# lxh623
有些字符识别不了,没办法正确拆分- <# :
- cls
- @echo off
- cd /d "%~dp0"
- powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%~f0'"
- pause
- exit
- #>
- $self=get-item -liter $args[0];
- $path=$self.Directory.FullName;
-
- $file1=".\jiansi.txt";
- $file2=".\caifen.txt";
- $file3=".\dengsi.txt";
-
- $file1=$file1 -replace '^\.',$path;
- $file2=$file2 -replace '^\.',$path;
- $file3=$file3 -replace '^\.',$path;
- if(-not (test-path -liter $file1)){Write-host ('"'+$file1+'" not found');exit;};
- if(-not (test-path -liter $file2)){Write-host ('"'+$file2+'" not found');exit;};
-
- $enc=New-Object System.Text.UTF8Encoding $False;
- $text1=[IO.File]::ReadAllLines($file1,$enc);
- $text2=[IO.File]::ReadAllLines($file2,$enc);
-
- $dic1=New-Object 'System.Collections.Generic.Dictionary[string,Object]';
- for($i=0;$i -lt $text2.count;$i++){
- $arr=$text2[$i].split('@!:', 2);
- if($arr.length -ge 2){
- if(-not $dic1.ContainsKey($arr[0])){
- [System.Collections.ArrayList]$tmp=@();
- $dic1.add($arr[0], $tmp);
- };
- };
- [void]$dic1[$arr[0]].add($text2[$i]);
- };
-
-
- $fs=New-Object System.IO.FileStream($file3, [System.IO.FileMode]::Create);
- $sw=New-Object System.IO.StreamWriter($fs, $enc);
- for($i=0;$i -lt $text1.count;$i++){
- write-host $text1[$i];
- $arr=$text1[$i].split('-', 2);
- if($dic1.ContainsKey($arr[0])){
- $line=$text1[$i];
- for($j=0;$j -lt $dic1[$arr[0]].count;$j++){
- $brr=$dic1[$arr[0]][$j].split('@!:', 2);
- $t=$brr[1].replace($arr[1], '');
- if($brr[1] -ne $t){
- $line=$line+'='+$t;
- break;
- };
- };
- $sw.WriteLine($line);
- }else{
- $sw.WriteLine($text1[$i]);
- };
- $sw.Flush();
- };
- $sw.Close();
- $fs.Close();
复制代码
|