- <# :
- cls&echo off&cd /d "%~dp0"&mode con lines=5000&rem bat存为ANSI/GB2312编码
- set "current=%cd%"
- powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0'|Out-String|Invoke-Expression"
- pause
- exit
- #>
- $current=$env:current;
-
- $folders=@"
- .\111
- .\333
- "@;
-
- $line_prefix=@'
- <Text name="123
- <Text name="234
- <Text name="763
- '@;
-
-
- $enc=New-Object System.Text.UTF8Encoding $False;
- $arr=$folders.trim() -split '[\r\n]+';
- $brr=@($line_prefix.trim() -split '[\r\n]+'|%{$_.trim().ToLower()});
- for($i=0;$i -lt $arr.length;$i++){
- if(test-path -literal $arr[$i]){
- $files=@(dir -literal $arr[$i] -recurse|?{('.xml' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
- for($j=0;$j -lt $files.length;$j++){
- write-host $files[$j].FullName;
- $s=New-Object -TypeName System.Collections.ArrayList;
- $text=[IO.File]::ReadAllLines($files[$j].FullName, $enc);
- for($k=0;$k -lt $text.count;$k++){
- $ismatch=$false;
- $line=$text[$k].trim().ToLower();
- for($p=0;$p -lt $brr.length;$p++){
- if($line.StartsWith($brr[$p])){
- $ismatch=$true;
- break;
- }
- }
- if(-not $ismatch){[void]$s.add($text[$k]);}
- }
- [IO.File]::WriteAllLines($files[$j].FullName, $s, $enc);
- }
- }else{
- write-host ($arr[$i]+' not found') -ForegroundColor yellow;
- }
- }
复制代码
|