本帖最后由 zaqmlp 于 2022-3-23 20:02 编辑
1- <# :
- cls&echo off&cd /d "%~dp0"&rem 编码ANSI
- powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText(\"%~f0\",[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
- pause
- exit
- #>
- $txtfile=".\文档\文件.txt";
- $uuidfile=".\随机UUID\uuid.txt";
- if(-not (test-path -literal $txtfile)){write-host ('"'+$txtfile+'" 未找到');exit;}
- $enc=[Text.Encoding]::GetEncoding('GB2312');
- $uuid='';
- if(test-path -literal $uuidfile){
- $text=[IO.File]::ReadAllText($uuidfile, $enc);
- $m=[regex]::match($text, '(?i)[\dA-F]{10,}');
- if($m.Success){$uuid=$m.groups[0].value;}
- }
- if($uuid -eq ''){$uuid=[System.Guid]::NewGuid().ToString("N").toUpper();}
- $text=[IO.File]::ReadAllText($txtfile, $enc);
- $text=[regex]::replace($text, '(@uuid@=)[^\r\n]*', {
- param($m);
- $m.groups[1].value+$uuid;
- });
- [IO.File]::WriteAllText($txtfile, $text, $enc);
复制代码
|