3

I created this batch file to compress my epub files into an epub.

It checks for an existing epub and deletes it.

It checks the current folder name and then simply creates a zip file with the same name. It then renames that .zip to a .epub

for %%a in (.) do set currentfolder=%%~na
del *.epub
7z a -tzip %currentfolder%.zip META-INF OPS mimetype
rename *.zip *.epub

However I do not pass validation with this epub file. http://validator.idpf.org/ gives me the following two errors that I need to fix.

  • Mimetype entry missing or not the first in archive
  • item (OPS/image/Thumbs.db) exists in the zip file, but is not declared in the OPF file

1.How do I force the mimetype file to be the first in the archive?

2.How do I remove this thumbs.db, I can see it in the archive but i don't see it in Explorer?

Thank you in advance

Morne
  • 1,623
  • 2
  • 18
  • 33

5 Answers5

2

Put mimetype as the first filespec after the zip name and it should be processed first.

Look up the file exclude feature of 7zip and use it with thumbs.db as it is a hidden file.

foxidrive
  • 40,353
  • 10
  • 53
  • 68
  • I have added the exclude tag and it works perfect thank you. The mimetype issue still isn't resolved. It seems no matter where i put the mimetype in the filespec, 7zip adds them alphabetically. – Morne Sep 17 '13 at 06:48
  • Use two 7Zip command lines. The first one will create the archive and include mimetype. The second will `add` to the archive with the remaining files. Regarding thumbs.db: your command only adds specific files so it shouldn't add thumbs.db anyway. – foxidrive Sep 17 '13 at 09:15
  • I used two 7zip command lines, but still get an error about mimetype missing. I don't think 7zip preserves the order that files were added in. – kristianp Dec 22 '19 at 06:15
2

Ferroao has the right idea, but it can be simplified:

cd "folder of epub content"

# add mimetype 1st
zip -0 -X ../file.epub mimetype

# add the rest
zip -9 -X -r -u ../file.epub *

The -u on the second command tells Zip to add only new/changed files, so it will skip mime type on the second pass.

Snow Coil
  • 21
  • 1
0

Put mimetype in first, but without compression.

cmd
  • 11,622
  • 7
  • 51
  • 61
Erik
  • 1
0

See this answer for a script that moves the mimetype to the start of the epub file, by adding it with the filename !mimetype in order for it to be first. Then renaming to mimetype within the zip file. https://superuser.com/a/966241

They key is to rename within the zip file like so:

"C:\Program Files\7-Zip\7z.exe" a myfile.zip !mimetype
"C:\Program Files\7-Zip\7z.exe" rn myfile.zip !mimetype mimetype
kristianp
  • 5,496
  • 37
  • 56
0

I couldn't with 7z, ended doing:

cd "folder of epub content"

# add mimetype 1st
zip -0 -X ../file.epub mimetype

# avoid writing it again in the next step, here I renamed
mv mimetype backup_mimetype

# add the rest
zip -9 -X -r ../file.epub *
Ferroao
  • 3,042
  • 28
  • 53