Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There are times when it is necessary for the files in a ZIP archive to be in a specific order (for example, I'm currently creating EPUBs, which require that the first entry in the ZIP be the mimetype file). How can I do this on Windows?

I'm currently using 7-Zip as my archiver, but I don't see an option for controlling file order. Can this be done with 7-zip? If not, what options do I have?

share|improve this question
Adding them in the order that they need to be should do this. Try zipping the mimetype file first, then adding the other files to the zip as a second operation. – Paul Feb 3 '12 at 0:25
@Paul — Surprisingly, that didn't work. :-/ – Ben Blank Feb 3 '12 at 1:01
Is it LIFO maybe? Can you try adding mimetype last? You are testing against an epub reader right, rather than just unzipping? – Paul Feb 3 '12 at 1:08
A application that requires the contents to be in a specific order is broken. – psusi Feb 3 '12 at 3:52
Sheesh, the authors of the spec need taken out back and beaten with a clue-by-four. – psusi Feb 3 '12 at 14:31

One way would be: Most archivers, and archive tools have the ability to append or add additional file items to the original archive. Create your archive with the items you want at the top , then add additional files items to that created archive. I know this works in windows own ZIP tools.

looks like the real answer is beyond me , here for C#

here for HTML (using 7z)

specificly this part

2.Open the sample-photo-book folder, and copy the file mimetype into the (empty) archive first.
3.Now, copy the other folders (META-INF and OEBPS) into the archive.

The contents of the mimetype file must not contain any leading padding or whitespace, must not begin with the Unicode signature (or Byte Order Mark), and the case of the MIME type string must be exactly as presented above. The mimetype file additionally must be neither compressed nor encrypted, and there must not be an extra field in its ZIP header.

share|improve this answer
I gave this a try in 7-zip (creating an archive with only mimetype, then adding the other files), but had no success. The mimetype data came first in the file, but the file table seems to be alphabetized. – Ben Blank Feb 3 '12 at 1:04
@BenBlank Make sure you aren't checking this using a zip client - they will re-order in a way that suits humans, not necessarily what an epub reader will see. – Paul Feb 3 '12 at 1:10
Presumably the problem is that 7-Zip likes to maintain it's directory in alpha order and then (necessarily) rewrites it when it closes the zip file. One could, in theory, fix this by editing the zip file with a hex editor or some sort of ad-hoc tool and rearranging the directory -- it's not particularly complicated. Editing would be simplified by including a dummy file that always sorts first. But then, of course, the technique in the above link should work too. – Daniel R Hicks Feb 3 '12 at 1:22
I used 7z l to list the contents of a zip, and they don't appear to be in any order (name, path, date, size...). So, using this command line may help determine the true order of the files in the zip. – Scott McClenning Feb 3 '12 at 1:26
@Paul — I'm checking by opening the .epub in a text editor and examining the file table directly, so it looks like this approach simply isn't working for me. I'm going to take the Python hammer to the problem and see if that doesn't fix it. – Ben Blank Feb 3 '12 at 2:35

7-zip GUI version:

  1. extract mimetype from EPUB file
  2. delete mimetype in EPUB file
  3. rename mimetype to !mimetype
  4. add !mimetype to EPUB file
  5. rename !mimetype to mimetype inside EPUB file

7-zip simple drag and drop version:

Go to 7-zip download page and download 7-Zip Extra: standalone console version, 7z DLL, Plugin for Far Manager (doesn't work with stable 9.20, but works well with 9.38 beta and 15.06 beta). Extract 7za.exe. Save code below as repair.bat file:

7za x %1 mimetype -y
7za d %1 mimetype
move /y mimetype !mimetype
7za a %1 !mimetype
del /f !mimetype
7za rn %1 !mimetype mimetype

Put 7za.exe and repair.bat in the same directory and simply drag your EPUB file on repair.bat.

share|improve this answer

Creating an EPUB requires a two step process, first add mimetype without any (!) compression, second add the other files/folders. So using 7z you could take the following commands:

7z a -mx=0 mimetype

To be able to use the wildcard * you should move the file mimetype to another folder and start the second step:

7z a -r *

After that rename the ZIP to EPUB and you're gone!

share|improve this answer
I have just tried this and I still get this error: Epubcheck Version 3.0.1 ERROR: C:/MYSELF/Books/1984---George-Orwell/1984---George-Orwell.epub: Mimetype entry missing or not the first in archive – Tomáš Zato Oct 17 '14 at 22:24

In my experience, the simplest answer (for Windows, 7, 64-bit) is to use Window's built-in Zip functionality. Use the "Send To" to send the mimetype to a new zipped folder, then use 7Zip to add the META-INF and OEBPS to the new zip. That seems to always work in terms of sequencing the mimetype file first. I have not had success performing this operation solely with 7-zip. (This is for ePUBS, but it should work, for sequencing, in other areas as well.)

I hope this helps someone else.

share|improve this answer

Using winrar did the trick for me. I added the mimetype to a zip-archive (uncompressed!), then later added the remaining folders, regular compression.

This solution did not work with 7-zip for me, as it keeps reordering files.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .