Skip to content

Instantly share code, notes, and snippets.

@arthurattwell
Created May 10, 2018 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arthurattwell/f9f4fb8c6c3736eac7ec70cbd5249b4c to your computer and use it in GitHub Desktop.
Save arthurattwell/f9f4fb8c6c3736eac7ec70cbd5249b4c to your computer and use it in GitHub Desktop.
Batch file for validating all the epubs in a folder with EpubCheck
:: Don't show these commands to the user
@echo off
:: Keep variables local, and expand at execution time not parse time
setlocal enabledelayedexpansion
:: Set the title of the window
title Validating epubs
:begin
echo This will run EpubCheck on all the epubs in this folder.
pause
:findEpubCheck
:: Check if epubcheck is in the PATH, and run it if it is
echo Finding EpubCheck...
:: Use a batch-file trick to get the location of epubcheck
:: https://blogs.msdn.microsoft.com/oldnewthing/20120731-00/?p=7003/
for /f %%i in ('where epubcheck.jar') do set epubcheckLocation=%%i
if "%epubcheckLocation%"=="" (
echo Couldn't find EpubCheck, sorry.
echo Please check that it's in your PATH.
goto begin
) else (
echo Found EpubCheck at %epubchecklocation%, running validation...
)
:timestamp
:: Create a timestamp for our log file
for /f "tokens=2-8 delims=.:/, " %%a in ("%date% %time%") do set timestamp=%%c-%%a-%%bT%%d-%%e-%%f
set epubCheckLogFile=epubcheck-log-%timestamp%
:runValidation
:: Now we can run validation on all the epubs in this folder
for %%f in ("*.epub") do (
:: Run EpubCheck, saving the error stream to a log file
echo Checking "%%~f" ...
call java -jar "%epubcheckLocation%" "%%~f" 2>> %epubCheckLogFile%.txt
)
:openLog
echo Opening EpubCheck log...
start %epubCheckLogFile%.txt
:finished
echo Done.
goto:EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment