本帖最后由 WHY 于 2022-12-15 10:44 编辑
- @echo off
- REM 替换 D:\\Firefox106 为当前脚本路径
- set "p=%~dp0"
- PowerShell "$arr = (gc -Literal '%~dp0extensions.json' -Enc UTF8 -ReadCount 0) -replace '(?<=\"path\":\")(?:(?!\"path\":\").)*(?=Profiles\\\\extensions|browser\\\\features)', '%p:\=\\%'; sc -Literal '%~dp0Result.json' -Value $arr -Enc UTF8"
- pause
复制代码 Test.ps1- #替换 D:\\Firefox106 为当前当前脚本路径
- #需PowerShell v3.0及以上版本
- $MyPath = $MyInvocation.MyCommand.Path -replace '\\[^\\]+$', '\';
- $json = gc -Literal ($MyPath + 'extensions.json') -Raw -Enc utf8 | ConvertFrom-Json;
-
- forEach( $obj In $json.addons ){
- $path = $obj.path -replace '^.*?\\(?=Profiles\\extensions|browser\\features)', $MyPath;
- $obj.path = $path;
- }
-
- $json | ConvertTo-Json -Depth 10 | sc -Literal ($MyPath + 'Result.json') -Enc utf8;
复制代码
|