View Single Post
Old 03-23-2011, 12:34 AM   #4
Lightsource
Junior Member
Lightsource doesn't litterLightsource doesn't litterLightsource doesn't litter
 
Lightsource's Avatar
 
Posts: 8
Karma: 216
Join Date: Mar 2011
Location: Houston, TX - USA
Device: Kindle 3
Powershell example script (ebook batch conversion)

I originally found this forum when looking for a solution to batch processing files (converting) using Calibre's command line interface. It seems there are a number of folks having the issue, and a number have suggested running the batch file from Powershell - didn't work for me.

Neither did prefacing each invocation of ebook-convert.exe with any combination of start, wait call or c/|!@#$%^&* variations. It will run once, then the command shell will simply not run a second instance of ebook-convert.exe. It doesn't start, it doesn't fail, no errors, it simply does nothing on any subsequent attempts to execute, unless you close the command prompt and open a new one.

I wanted to do this because I had about 960 epub books that my sister asked me to convert for her new Kindle (and since I didn't want to load all of her romance novels into my Calibre database, I didn't want to do this from the GUI).

I've seen a dozen posts around the internet grousing about this behavior, and a number of them just skulked off and said something like, well, I guess I'll just go do it in Powershell. This was totally unhelpful to me, as no one actually DID IT and shared.

So, I've done it and I'm sharing. Attached is a Powershell script that will run multiple instances of ebook-convert.exe sequentially. It will allow you to batch convert ebooks using Calibre's command line conversion utility.

This script is hard coded to run a conversion from epub to mobi, however, it is well commented and even if you don't know how to code in Powershell, you should be able to read it and modify it to do any supported conversion.

The only caveat is, in order to run Powershell scripts, you have to install Powershell. It's free, and runs on just about any version of Windows.

Powershell is available from Microsoft here:
http://support.microsoft.com/kb/968929
(the link is at the bottom of the page - there's a separate installer for each platform)

You can also just google the following phrase and find it:
"download Powershell site:microsoft.com"

Since PS is such a powerful tool (you can access machines anywhere in your network and remote-execute scripts on them), it is disabled out of the box - once you install it, you have to enable script execution - there's a very clear and concise article about it here:
http://www.tech-recipes.com/rx/2513/...cript_support/

Once you have PS installed and enabled, you can just run this script - It will ask you for the directory of your ebooks (the ones you want to convert), then will grab all of the epub files and process them one by one. Since each conversion takes about a minute (on my system, anyway - dual proc 32-bit XP), if you have 60 files, it will take about an hour; 120 files would take roughly two hours, and so on.

Download the script, read the comments. If you want to convert say, LIT to EPUB or PDB to HTML, you can just modify the script - it's commented so that you should be able to figure out exactly what to change and where to do what you need, without being a scriptmaster.

I have a number of revisions in mind for this, but it's a good starting point, and it works as is - hope this helps those of us that are frustrated by the lack of a batch conversion tool.
Attached Files
File Type: zip CalibreConvert_EpubToMobi.zip (1.7 KB, 276 views)

Last edited by Lightsource; 03-23-2011 at 12:14 PM. Reason: Updating Attachment
Lightsource is offline   Reply With Quote