- <# :
- @echo off
- PowerShell -NoProfile -C ". ([ScriptBlock]::Create((gc -Literal '%~f0') -join \"`r`n\"))"
- pause & exit/b
- #>
-
- $path1 = 'D:\DATA1\'; #源目录
- $path2 = 'D:\DATA2\'; #目标目录
-
- if( -Not [IO.Directory]::Exists($path2) ){ $null = md $path2; }
-
- forEach( $file In (dir -Literal $path1 -Filter *.txt) ){
- $dic = New-Object 'System.Collections.Generic.Dictionary[string, [Collections.ArrayList]]';
- $res = [Collections.ArrayList]@();
-
- forEach( $strLine In [IO.File]::ReadAllLines($file.FullName, [Text.Encoding]::UTF8) ){
- $arr = $strLine -split '->';
- if( $arr.Count -eq 2 ){
- $key = $arr[0].ToLower();
- if( -Not $dic.ContainsKey($key) ){
- $dic.Add( $key, @($strLine) );
- }else{
- [void]$dic[$key].Add( $arr[1] );
- }
- }
- }
-
- forEach( $key In $dic.Keys ){
- [void]$res.Add( $dic[$key] -join ' ' );
- }
-
- [IO.File]::WriteAllLines( $path2 + $file.Name, $res, [Text.Encoding]::UTF8 );
- }
复制代码
|