标题: 【完成】50元求epub的替换 [打印本页]
作者: lxh623 时间: 2020-7-21 18:07 标题: 【完成】50元求epub的替换
本帖最后由 lxh623 于 2020-7-23 08:32 编辑
以前有个结果,当时是删除部分内容。
这次想替换内容。
上次在 http://www.bathome.net/thread-53745-1-1.html
文本a(UTF8)写入以下内容:
殤\t殤<span class="corr">【商shāng】</span>
上万行。想用\t(制表符)后面的内容替换\t前面的内容,地点是解包后的html和xhtml文件。
epub的批处理最好给出三个,一个解包,一个替换,一个打包。
上次是一个。
谢谢!
作者: zaqmlp 时间: 2020-7-21 19:25
本帖最后由 zaqmlp 于 2020-7-21 19:31 编辑
- @echo off
- rem 解包
- set "zipexe=C:\Program Files\7-Zip\7z.exe"
- set "oldfolder=D:\xxx\epub原件夹"
- set "newfolder=E:\yyy\epub解包后"
- if not exist "%zipexe%" (echo;"%zipexe%" not found&pause&exit)
- if not exist "%oldfolder%" (echo;"%oldfolder%" not found&pause&exit)
- if not exist "%newfolder%" (md "%newfolder%")
- for /f "delims=" %%a in ('dir /a-d/b/s "%oldfolder%\*.epub"') do (
- echo;解包 "%%a"
- echo;--------------------------------
- "%zipexe%" x -tzip "%%a" -o"%newfolder%\%%~na\"
- )
- pause
- exit
复制代码
作者: zaqmlp 时间: 2020-7-21 19:49
本帖最后由 zaqmlp 于 2020-7-21 20:02 编辑
- <# :
- cls
- @echo off
- rem 替换
- mode con lines=5000
- cd /d "%~dp0"
- powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%~dp0'"
- pause
- exit
- #>
- $path=$args[0].trimend('\');
- $txtfile=".\a.txt";
- $oldfolder="E:\yyy\epub解包后";
- $ext=@('.html', '.xhtml');
-
- $txtfile=$txtfile -replace '^\.',$path;
- if(-not (test-path -liter $txtfile)){Write-host ('"'+$txtfile+'" not found');exit;};
- if(-not (test-path -liter $oldfolder)){Write-host ('"'+$oldfolder+'" not found');exit;};
- $Utf8NoBom=New-Object System.Text.UTF8Encoding $False;
- $text=[IO.File]::ReadAllLines($txtfile, $Utf8NoBom);
- $folders=@(dir -liter $oldfolder|?{$_ -is [System.IO.DirectoryInfo]});
- for($i=0;$i -lt $folders.count;$i++){
- write-host $folders[$i].FullName;
- $files=@(dir -liter $folders[$i].FullName -recurse|?{($ext -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])});
- for($j=0;$j -lt $files.count;$j++){
- write-host $files[$j].FullName.substring($folders[$i].FullName.length);
- $htmltext=[IO.File]::ReadAllText($files[$j].FullName, $Utf8NoBom);
- for($k=0;$k -lt $text.count;$k++){
- $arr=$text[$k] -split '\t',2;
- $htmltext=$htmltext.replace($arr[0],$arr[1]);
- };
- [IO.File]::WriteAllText($files[$j].FullName, $htmltext, $Utf8NoBom);
- };
- };
复制代码
作者: zaqmlp 时间: 2020-7-21 19:54
- @echo off
- rem 打包
- set "zipexe=C:\Program Files\7-Zip\7z.exe"
- set "oldfolder=E:\yyy\epub解包后"
- set "newfolder=E:\zzz\epub打包后"
- if not exist "%zipexe%" (echo;"%zipexe%" not found&pause&exit)
- if not exist "%oldfolder%" (echo;"%oldfolder%" not found&pause&exit)
- if not exist "%newfolder%" (md "%newfolder%")
- for /f "delims=" %%a in ('dir /ad/b "%oldfolder%\"') do (
- echo;打包 "%oldfolder%\%%~nxa"
- echo;-----------------------------------
- if exist "%newfolder%\%%~nxa.epub" del /a /f /q "%newfolder%\%%~nxa.epub"
- "%zipexe%" a -tzip "%newfolder%\%%~nxa.zip" "%oldfolder%\%%~nxa\*"
- ren "%newfolder%\%%~nxa.zip" "%%~nxa.epub"
- rem rd /s /q "%oldfolder%\%%~nxa\"
- )
- rem rd /s /q "%oldfolder%\"
- pause
- exit
复制代码
作者: lxh623 时间: 2020-7-23 08:18
回复 4# zaqmlp
感谢帮助,请查收。
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |