本帖最后由 zaqmlp 于 2022-4-1 22:13 编辑
报酬有点少- <# :
- cls&echo off&cd /d "%~dp0"&rem 编码ANSI
- powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText(\"%~f0\",[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
- pause
- exit
- #>
- $xmlfolder=".\文档";
- if(-not (test-path -literal $xmlfolder)){write-host ('"'+$xmlfolder+'" 未找到');exit;}
- $enc=New-Object System.Text.UTF8Encoding $False;
- $files=@(dir -literal $xmlfolder -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, '\b(x|y|w|h|expression)="([^"]+?)"','IgnoreCase');
- foreach($it in $m1){
- $oldword=$it.groups[0].value;
- $ov=$it.groups[2].value;
- $nv=[regex]::replace($ov, '(?<=^|,| )[-+]?\d+(?:[-+]\d+){1,}', {
- param($z);
- $s=Invoke-Expression $z.groups[0].value;
- return $s;
- })
- $nv=[regex]::replace($nv, '(?<=[^\d+-])(?:[-+]\d+){2,}|(?<=#\d+)(?:[-+]\d+){2,}', {
- param($z);
- $s=Invoke-Expression $z.groups[0].value;
- if($s -match '^-'){return $s;}else{return ('+'+$s.toString());}
- })
- $newword=$oldword.replace($ov, $nv);
- $text=$text.replace($oldword, $newword);
- }
- [IO.File]::WriteAllText($files[$i].FullName, $text, $enc);
- }
复制代码
|