返回列表 发帖
本帖最后由 newswan 于 2023-5-3 14:05 编辑

假设 content.opf 编码是 UTF8
如果显示正确,去掉第十行的 #
$root = "."
$insert = '    <item id="Cbeta.ttf" href="Fonts/Cbeta.ttf" media-type="application/x-font-ttf"/>'
$fld = Get-ChildItem -Directory -Path $root
$fld | ForEach-Object {
    if ( Test-Path (Join-Path $_.FullName "\Fonts\Cbeta.ttf") ) {
        $file = Get-Content -Encoding UTF8 (Join-Path $_.FullName "content.opf")
        $file = $file -replace '(?=</manifest>)',($insert + "`r`n")
        $file
#       $file | Out-File -Encoding UTF8 (Join-Path $_.FullName "content.opf")
    }
}COPY
如果想要用批处理,把这行添加到上面第一行
@cd /d %~dp0 & powershell -command "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" & pause & exit/bCOPY
1

评分人数

TOP

避免重复插入。前提是 原文件没有那行,不论在什么位置
$root = "."
$str1 = '</manifest>'
$str2 = '    <item id="Cbeta.ttf" href="Fonts/Cbeta.ttf" media-type="application/x-font-ttf"/>'
$fld = Get-ChildItem -Directory -Path $root
$fld | ForEach-Object {
    if ( Test-Path (Join-Path $_.FullName "\Fonts\Cbeta.ttf") ) {
        $file = Get-Content -Encoding UTF8 (Join-Path $_.FullName "content.opf")
        if ( -not ($file -match $str2) ) {
            $file = $file -replace "(?=$str1)",($str2 + "`r`n")
            $file | Out-File -Encoding UTF8 (Join-Path $_.FullName "content.opf")
        }
    }
}COPY
1

评分人数

TOP

返回列表