- <# :
- cls
- @echo off
- cd /d "%~dp0"
- powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%~dp0'"
- pause
- exit
- #>
- $path=$args[0];
- $outfile=$path+'#result.csv';
- $enc=[Text.Encoding]::UTF8;
- $fs=New-Object System.IO.FileStream($outfile, [System.IO.FileMode]::Create);
- $sw=New-Object System.IO.StreamWriter($fs, $enc);
- $files=@(dir -liter $path -recurse|?{('.xml' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
- for($i=0;$i -lt $files.length;$i++){
- write-host $files[$i].FullName;
- $text=[IO.File]::ReadAllText($files[$i].FullName, $enc);
- $m1=[regex]::matches($text, '<char xml:id="[^"]*?">([\s\S]+?)</char>');
- if($m1.count -ge 1){
- foreach($k in $m1){
- $arr=@('','','','','');
- $a=[regex]::match($k.groups[1].value,'[^>]+(?=</charName>)');
- if($a.success){$arr[0]=$a.groups[0].value;};
- $b=[regex]::match($k.groups[1].value,'composition</localName>\s*?<value>([\s\S]+?)</value>');
- if($b.success){$arr[1]='"'+$b.groups[1].value+'"';};
- $c=[regex]::match($k.groups[1].value,'normalized form</localName>\s*?<value>([\s\S]+?)</value>');
- if($c.success){$arr[2]='"'+$c.groups[1].value+'"';};
- $d=[regex]::match($k.groups[1].value,'<mapping type="[^"]*?unicode">([\s\S]+?)</mapping>');
- if($d.success){$arr[3]=$d.groups[1].value;};
- $e=[regex]::match($k.groups[1].value,'type="PUA">([\s\S]+?)</mapping>');
- if($e.success){$arr[4]=$e.groups[1].value;};
- $line=$arr -join ',';
- $sw.WriteLine($line);
- $sw.Flush();
- };
- };
- };
- $sw.Close();
- $fs.Close();
复制代码
|