[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 newswan 于 2023-5-3 14:05 编辑

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

评分人数

TOP

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

评分人数

TOP

返回列表