返回列表 发帖
本帖最后由 zaqmlp 于 2019-5-22 10:12 编辑
@echo off
cd /d "%~dp0"
set "folder=结果"
md "%folder%" 2>nul
powershell -NoProfile -ExecutionPolicy bypass ^
    $files=@(dir^|?{($_ -is [System.IO.FileInfo]) -and ($_.Extension -eq '.xml')});^
    $arr='ABCDEFGHIJKLMNOPQRSTUVWXYZ'.toCharArray();^
    for($i=0;$i -lt $files.length;$i++){^
        write-host $files[$i].Name;^
        $dic=New-Object 'System.Collections.Generic.Dictionary[string,string]';^
        $list=New-Object 'System.Collections.Generic.Dictionary[string,string]';^
        $text=[IO.File]::ReadAllText($files[$i].FullName, [Text.Encoding]::UTF8);^
        $m=[regex]::matches($text,'name=\""([^^\""]+)\""');^
        $newtext=$text;^
        if($m.Count -ge 1){^
            for($j=0;$j -lt $m.Count;$j++){^
                $kw=$m[$j].groups[1].value;^
                if(@('=','%%') -notcontains $kw){^
                    if(-not $dic.ContainsKey($kw)){^
                        $c=@(get-random -input $arr -count 3) -join '';^
                        while($list.ContainsKey($c)){$c=@(get-random -input $arr -count 3) -join '';};^
                        $list.add($c,'');^
                        $newtext=$newtext.replace($m[$j].groups[0].value,'name=\"'+$c+'\"');^
                        $dic.add($kw,$c);^
                        $n++;^
                    };^
                };^
            };^
            $k=@($dic.keys^|sort {$_.length} -des);^
            $newtext=[regex]::replace($newtext,'(?^<==)\""[^^\""]+?\""',{param($a);$b=$a.value;foreach($it in $k){$b=$b.replace(('@'+$it),('@'+$dic[$it])).replace(('#'+$it),('#'+$dic[$it]));};$b});^
            [IO.File]::WriteAllText(('%folder%\'+$files[$i].Name), $newtext, [Text.Encoding]::UTF8);^
        };^
    }
pauseCOPY
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

回复 4# smss

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

TOP

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

TOP

回复 36# smss

“中伤”是你的用词,我只是说了会乱码的事实,而且你自己23楼也验证了;需求一再变动,加价很合理,买卖不成,仁义要在,你在这煽动情绪也没用
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

回复 41# smss

事实你最初的方式就是不行呀,如果只按你最初的需求,替换后为什么你要一再变更需求,而且我让你找出替换后不对的地方,你一直跟我扯手机不行有什么用,你要告诉我哪里替换不对
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

返回列表