回复 8# lxh623
保存为 合并epub.bat,编码ANSI,此脚本放到解包后的文件夹内. | | | | | | | | | | | | | | | | | | | | | Get-ChildItem -Path . | Where-Object { $_ -is [IO.DirectoryInfo] -and $_.FullName -ne $env:batchfile } | Group-Object -Property @{ | | Expression = { $_.Name -replace '第\s+\d+\s+卷' } | | } | ForEach-Object { | | $di1 = $_.Group | Where-Object { $_.Name -match '第\s+(\d+)\s+卷' -and $Matches[1] -eq '1' } | Select-Object -First 1 | | if ($null -eq $di1) { return } | | if($_.Group.Count -le 1){return} | | $opf = [IO.Path]::Combine($di1.FullName, 'OEBPS\content.opf') | | $xml = [IO.File]::ReadAllText($opf) | | if (-not $?) { return } | | | | | | $di1.Name | Out-Host | | $_.Group | Where-Object { $_ -ne $di1 } | ForEach-Object { | | | | | | Get-ChildItem -LiteralPath ([IO.Path]::Combine($_.FullName, 'OEBPS\pages')) -Filter *.xhtml | ForEach-Object { | | $fi2 = $_ | Copy-Item -Destination ([IO.Path]::Combine($di1.FullName, "OEBPS\pages")) -PassThru | | if ($fi2) { | | $xml = $xml.Replace("</manifest>", @" | | <item id="$($fi2.Name)" href="Text/$($fi2.Name)" media-type="application/xhtml+xml"/></manifest> | | "@).Replace("</spine>", @" | | <itemref idref="$($fi2.Name)"/></spine> | | "@) | | } | | } | | Get-ChildItem -LiteralPath ([IO.Path]::Combine($_.FullName, 'OEBPS\style')) -Filter *.css | ForEach-Object { | | $fi2 = $_ | Copy-Item -Destination ([IO.Path]::Combine($di1.FullName, "OEBPS\style")) -PassThru | | if ($fi2) { | | $xml = $xml.Replace("</manifest>", @" | | <item id="$($fi2.Name)" href="Styles/$($fi2.Name)" media-type="text/css"/></manifest> | | "@) | | } | | | | } | | } | | [IO.File]::WriteAllText($opf, $xml) | | }COPY |
|