[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
完全看不懂要提取什么,发图示标明提取位置并把测试文件打包上传或发网盘
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

本帖最后由 zaqmlp 于 2020-9-11 22:18 编辑

回复 3# lxh623
  1. <# :
  2. cls
  3. @echo off
  4. cd /d "%~dp0"
  5. powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%~dp0'"
  6. pause
  7. exit
  8. #>
  9. $path=$args[0];
  10. $outfile=$path+'#result.csv';
  11. $enc=[Text.Encoding]::UTF8;
  12. $fs=New-Object System.IO.FileStream($outfile, [System.IO.FileMode]::Create);
  13. $sw=New-Object System.IO.StreamWriter($fs, $enc);
  14. $files=@(dir -liter $path -recurse|?{('.xml' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
  15. for($i=0;$i -lt $files.length;$i++){
  16.   write-host $files[$i].FullName;
  17.   $text=[IO.File]::ReadAllText($files[$i].FullName, $enc);
  18.   $m1=[regex]::matches($text, '<char xml:id="([^"]*?)">([\s\S]+?)</char>');
  19.   if($m1.count -ge 1){
  20.   foreach($k in $m1){
  21.     $arr=@($files[$i].BaseName,'','','','','','','','','');
  22.    
  23.     $a=$k.groups[1].value;
  24.     $arr[1]=$a;
  25.     $b=[regex]::match($k.groups[2].value,'[^>]+(?=</charName>)');
  26.     if($b.success){$arr[2]=$b.groups[0].value;};
  27.    
  28.     $m2=[regex]::matches($k.groups[2].value, '(?<=<value>).+?(?=</value>)');
  29.     $n=3;
  30.     if($m2.count -ge 1){
  31.         foreach($v in $m2){
  32.             $arr[$n]=$v.groups[0].value;
  33.             $n++;
  34.         };
  35.     };
  36.    
  37.     $f=[regex]::match($k.groups[2].value,'<mapping type="[^"]*?unicode">([\s\S]+?)</mapping>');
  38.     if($f.success){$arr[6]=$f.groups[1].value;};
  39.    
  40.     $g=[regex]::match($k.groups[2].value,'type="PUA">([\s\S]+?)</mapping>');
  41.     if($g.success){$arr[7]=$g.groups[1].value;};
  42.    
  43.     $h=[regex]::match($k.groups[2].value,'cb:dec="([^"]+?)".+?type="PUA"');
  44.     if($h.success){$arr[8]=$h.groups[1].value;};
  45.    
  46.     $reg='<g ref="#'+$a+'">(.+?)</g>'
  47.     $p=[regex]::match($text, $reg);
  48.     if($p.success){$arr[9]=$p.groups[1].value;};
  49.    
  50.     $line=$arr -join ',';
  51.     $sw.WriteLine($line);
  52.     $sw.Flush();
  53.   };
  54.   };
  55. };
  56. $sw.Close();
  57. $fs.Close();
复制代码
1

评分人数

提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

返回列表