标题: 【完成】文件复制与修改(80元) [打印本页]
作者: lxh623 时间: 2024-11-6 19:17 标题: 【完成】文件复制与修改(80元)
本帖最后由 lxh623 于 2024-11-6 20:29 编辑
1、J:\大藏经修改\modepub\epub解包后
2、J:\大藏经修改\epub解包后
路径1的每一个下面有许多子文件夹。比如,T01n0092--十支居士八城人经--後汉 安世高译\OEBPS下面有Fonts文件夹以及文件toc.ncx,复制到2的对应位置。后者是替换。
content.opf里面 </manifest>前面添加一行。- <item id="Cbeta.ttf" href="Fonts/Cbeta.ttf" media-type="application/x-font-ttf"/>
复制代码
谢谢!
作者: zaqmlp 时间: 2024-11-6 20:05
bat存为ANSI/GB2312编码- <# :
- cls&echo off&cd /d "%~dp0"&mode con lines=5000
- path %SYSTEMROOT%\System32\WindowsPowerShell\v1.0;%path%
- powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0'|Out-String|Invoke-Expression"
- pause
- exit
- #>
- $oldfolder="J:\大藏经修改\modepub\epub解包后";
- $newfolder="J:\大藏经修改\epub解包后";
- $addline=' <item id="Cbeta.ttf" href="Fonts/Cbeta.ttf" media-type="application/x-font-ttf"/>';
- if(-not (test-path -literal $oldfolder)){write-host ('"'+$oldfolder+'" path error or not exist');exit;}
- if(-not (test-path -literal $newfolder)){write-host ('"'+$newfolder+'" path error or not exist');exit;}
- $enc=New-Object System.Text.UTF8Encoding $False;
- $folders=@(dir -literal $oldfolder|?{$_ -is [System.IO.DirectoryInfo]});
- for($i=0;$i -lt $folders.length;$i++){
- write-host $folders[$i].Name;
- $newpath=$newfolder+"\"+$folders[$i].Name;
- $fd1=$folders[$i].FullName+"\OEBPS\Fonts";
- $fd2=$newpath+"\OEBPS\Fonts";
- if(test-path -literal $fd1){
- remove-item -literal $fd2 -recurse -force -ErrorAction SilentlyContinue;
- copy-item -literal $fd1 $fd2 -recurse -force -ErrorAction SilentlyContinue;
- }
- $f1=$folders[$i].FullName+"\OEBPS\toc.ncx";
- $f2=$newpath+"\OEBPS\toc.ncx";
- if(test-path -literal $f1){
- copy-item -literal $f1 $f2 -force -ErrorAction SilentlyContinue;
- }
- $files=@(dir -literal $newpath -recurse|?{('content.opf' -eq $_.Name) -and ($_ -is [System.IO.FileInfo])});
- for($j=0;$j -lt $files.length;$j++){
- $text=[IO.File]::ReadAllText($files[$j].FullName, $enc);
- $text=$text -replace '(?=<\/manifest>)',$addline;
- [IO.File]::WriteAllText($files[$j].FullName, $text, $enc);
- }
- }
复制代码
作者: flashercs 时间: 2024-11-6 20:19
- <#*,:
- @echo off
- cd /d "%~dp0"
- set "batchfile=%~f0"
- Powershell -ExecutionPolicy Bypass -C "Set-Location -LiteralPath ([Environment]::CurrentDirectory);. ([ScriptBlock]::Create([IO.File]::ReadAllText($env:batchfile,[Text.Encoding]::GetEncoding(0) )) )"
- pause
- exit /b
- #>
- # 复制文件
- # 1、J:\大藏经修改\modepub\epub解包后
- # 2、J:\大藏经修改\epub解包后
-
- $dir1 = "J:\大藏经修改\modepub\epub解包后"
- $dir2 = "J:\大藏经修改\epub解包后"
-
- Robocopy.exe $dir1 $dir2 *.ttf *.ttc toc.ncx /S /MT
-
- Get-ChildItem -Path "$dir2\*" -Filter content.opf -Recurse | Where-Object { $_ -is [IO.FileInfo] } | ForEach-Object {
- try {
- $_ | Resolve-Path -Relative
- $text = [IO.File]::ReadAllText($_.FullName)
- $text = $text.Replace('</manifest>', @'
- <item id="Cbeta.ttf" href="Fonts/Cbeta.ttf" media-type="application/x-font-ttf"/>
- </manifest>
- '@)
- [IO.File]::WriteAllText($_.FullName, $text)
- } finally {
-
- }
- trap {}
- }
复制代码
作者: lxh623 时间: 2024-11-6 20:29
谢谢!请查收!
作者: lxh623 时间: 2024-11-12 19:25
有两个问题,主要是我这边才发现的。
第一、文件经过别的软件转换,解包后,文件夹结构不一样。能不能在下面搜索toc.ncx,然后替换。
第二、content.opf位置也不一样。但是,修改了。<item id前面有四个空格,</manifest>转行后前面有两个空格。
麻烦一下!
作者: flashercs 时间: 2024-11-13 00:06
回复 5# lxh623 - <#*,:
- @echo off
- cd /d "%~dp0"
- set "batchfile=%~f0"
- Powershell -ExecutionPolicy Bypass -C "Set-Location -LiteralPath ([Environment]::CurrentDirectory);. ([ScriptBlock]::Create([IO.File]::ReadAllText($env:batchfile,[Text.Encoding]::GetEncoding(0) )) )"
- pause
- exit /b
- #>
- # 复制文件
- # 1、J:\大藏经修改\modepub\epub解包后
- # 2、J:\大藏经修改\epub解包后
-
- $dir1 = "J:\大藏经修改\modepub\epub解包后"
- $dir2 = "J:\大藏经修改\epub解包后"
-
- # Robocopy.exe $dir1 $dir2 *.ttf *.ttc /S /MT
- Get-ChildItem -LiteralPath $dir1 | Where-Object { $_ -is [IO.DirectoryInfo] } | ForEach-Object {
- try {
- $_.Name
- $root1 = $_.FullName
- $root2 = [IO.Path]::Combine($dir2, $_.Name)
- if ([IO.Directory]::Exists($root2)) {
- $toc1 = Get-ChildItem -LiteralPath $root1 -Filter toc.ncx -Recurse | Where-Object { $_ -is [IO.FileInfo] } | Select-Object -First 1
- $toc2 = Get-ChildItem -LiteralPath $root2 -Filter toc.ncx -Recurse | Where-Object { $_ -is [IO.FileInfo] } | Select-Object -First 1
- if ($toc1 -and $toc2) {
- $toc1 | Copy-Item -Destination $toc2.FullName -Force
- }
- $opf2 = Get-ChildItem -LiteralPath $root2 -Filter content.opf -Recurse | Where-Object { $_ -is [IO.FileInfo] } | Select-Object -First 1
- if ($opf2) {
- $text = [IO.File]::ReadAllText($opf2.FullName)
- $text = $text.Replace('</manifest>', @'
- <item id="Cbeta.ttf" href="Fonts/Cbeta.ttf" media-type="application/x-font-ttf"/>
- </manifest>
- '@)
- [IO.File]::WriteAllText($opf2.FullName, $text)
- $fonts1 = Get-ChildItem -LiteralPath $root1 -Filter Fonts -Recurse | Where-Object { $_ -is [IO.DirectoryInfo] } | Select-Object -First 1
- if ($fonts1) {
- $fonts2 = [IO.Path]::Combine([IO.Path]::GetDirectoryName($opf2.FullName), 'Fonts')
- Robocopy.exe ($fonts1.FullName) $fonts2 * /S /MT
- }
- }
- }
- } finally {
-
- }
- trap {}
- }
复制代码
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |