Thread: doc to epub
View Single Post
Old 03-05-2010, 12:43 PM   #49
adikira
Member
adikira is on a distinguished road
 
Posts: 11
Karma: 66
Join Date: Mar 2010
Device: Sony Reader Daily (PRS-900)
Welcome. I use a lot of Unix shell scripting at work but at home I still use Windows. When it comes to command line scripting Windows completely sucks! I may give powershell a try though.

Anyway, I updated the batch file to give more flexibility. It can take two arguments the file extension that you are converting from and the extension you are converting to (which defaults to epub if missing). If the extension you are converting from is doc or docx it first runs AbiWord to convert to html first otherwise it just uses Caliber's convertor.

It should be saved to a batch file such as "convert.bat." It's recommended that this file (convert.bat) is saved in the Windows directory so that it's in the PATH variable and can be called up from any folder. Otherwise the full path the the convert.bat needs to be specified or it needs to be in the current folder (of course).


Quote:
@ECHO OFF
if "%1"=="" GOTO USAGE
if "%1"=="doc" GOTO ABI
if "%1"=="docx" GOTO ABI
SET doAbi=no

:CALIBRE
if "%2"=="" SET ext2=epub
if "%2"!==!"" SET ext2=%2
if "%doAbi%"=="yes" SET ext1=html
if "%doAbi%"=="no" SET ext1=%1
echo Converting "%ext1%" to "%ext2%" using Calibre
for %%I in (*.%ext1%) do "%PROGRAMFILES%\Calibre2\ebook-convert.exe" "%%I" "%%~nI.%ext2%"
GOTO END

:ABI
SET doAbi=yes
echo Converting "%1" to "html" using AbiWord
for %%I in (*.%1) do "%PROGRAMFILES%\AbiWord\bin\AbiWord.exe" --to=html "%%I"
GOTO CALIBRE

:USAGE
echo "Usage %0 <first_extension> <second_extension>"
echo "Example: %0 doc epub"
echo "If <second_extension> is not specified it defaults to 'epub'"

:END

Last edited by adikira; 03-05-2010 at 12:47 PM.
adikira is offline   Reply With Quote