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?

  • 3
    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
  • 1
    @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
  • 3
    A application that requires the contents to be in a specific order is broken.
    – psusi
    Feb 3 '12 at 3:52
  • 4
    Sheesh, the authors of the spec need taken out back and beaten with a clue-by-four.
    – psusi
    Feb 3 '12 at 14:31

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.


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# https://stackoverflow.com/questions/5898787/creating-an-epub-file-with-a-zip-library

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.

  • 1
    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
  • 2
    @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. Feb 3 '12 at 1:22
  • I used 7z l filename.zip 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. 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

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 dummy.zip 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 dummy.zip *

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

  • 1
    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 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.


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.


I had this same problem when working with EPUB-files.

On Windows 7 I fixed it with this strange trick where i made sure that I sorted all of the files that i was going to make in to a zip in a way that made mimetype the file on top (sorting them by size usually). Then I made sure that i marked all of the files from top to bottom with my cursor before sending them to a compressed (zip) folder (like this: https://support.microsoft.com/en-us/help/14200/windows-compress-uncompress-zip-files). After that I could change the name and filetype to whatever.epub.

However, after I upgraded to Windows 10 this trick did not work anymore. Luckily I have found another way. First you send the file you want at the top (mimetype) in the zip file to a compressed(zip) folder. Make sure it is only that file. Than I take the other files i want to zip (two folder in my case) mark them with the cursor and drag them up to the zip file i just created. Windows will then add the new files to the zip file, and keep the file you originally ziped on top.

  • 1
    Can you clearly indicate what the answer to the author's question is? Upgrading to Windows 10 is not really an answer to this question. You should concentrate on how you fixed it, provide specifics, your statements are way to broad. If I were to reproduce the original problem, I would be unable to solve it with your answer.
    – Ramhound
    Oct 19 '16 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.