本帖最后由 WHY 于 2018-2-2 22:24 编辑
- function MergeFiles($chsFile, $engFile){
- $hash = @{}; $s1 = $s2 = '';
- ForEach($strLine In (type $chsFile)){
- If($s1 -like '[0-9][0-9]:*') { $hash[$s1] = $strLine; }
- $s1 = $strLine;
- }
- ForEach($strLine In (type $engFile)){
- If($s2 -like '[0-9][0-9]:*'){$strLine + ' ' + $hash[$s2];}
- $s2 = $strLine;
- }
- }
-
- $chsDir = 'C:\Users\CH6\Desktop\TEDTXTUNICODE\chs1203';
- $engDir = 'C:\Users\CH6\Desktop\TEDTXTUNICODE\eng1246';
- $mergeDir = 'C:\Users\CH6\Desktop\TEDTXTUNICODE\merge';
-
- If(!(Test-Path $mergeDir)){$null = md $mergeDir;}
-
- ForEach($eng In (dir ($engDir + '\*.txt'))){
- $chsFile = $chsDir + '\' + $eng.Name;
- If(Test-Path $chsFile){
- $arr = MergeFiles $chsFile $eng.FullName;
- Set-Content ($mergeDir + '\' + $eng.Name) $arr -Enc unicode;
- }
- }
-
- [Console]::Write('Done');
- [Console]::ReadLine()
复制代码
|