Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
FREEDOM251

Freedom251 › Blog › 7-Zip

How to Control the Sort Order of Files in a ZIP Archive

By Freedom251 Team · · 5 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Yes—you can control the order in which a ZIP creator writes entries, but you cannot force every archive viewer or extractor to display or process that order. Build the archive from an explicit, validated list, then inspect its member list. If sequence affects meaning, include a manifest or index instead of relying on ZIP order alone.

What “ZIP order” actually means

Several different sequences are often confused:

  • Physical entry order: the order of local headers and file data written into the archive.
  • Central-directory order: the order of metadata records at the end of the ZIP.
  • Display order: how Explorer, Finder, 7-Zip, or another viewer sorts the list.
  • Extraction order: the sequence an extractor creates files and directories.

The ZIP specification permits arbitrary storage order and does not require central-directory entries to match physical file order. Many programs list entries in the order they find them, but a viewer may sort by name, type, date, size, or a user-selected column. See the format notes in the ZIP specification documentation.

As an Amazon Associate I earn from qualifying purchases.

The reliable method: create a new ZIP from an ordered list

Do not archive a directory blindly when sequence matters. Pass files one at a time in the required order and verify the result.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from pathlib import Path
from zipfile import ZipFile, ZIP_DEFLATED

root = Path("package")
order = [
    "01-read-me.txt",
    "02-install.pdf",
    "03-example.csv",
    "04-license.txt",
]

seen = set()
with ZipFile("package.zip", "w", compression=ZIP_DEFLATED) as zf:
    for relative_name in order:
        if relative_name in seen:
            raise ValueError(f"Duplicate archive name: {relative_name}")
        seen.add(relative_name)

        source = root / relative_name
        if not source.is_file():
            raise FileNotFoundError(f"Missing file: {source}")
        zf.write(source, arcname=relative_name)

with ZipFile("package.zip") as zf:
    actual = zf.namelist()

if actual != order:
    raise RuntimeError(f"Unexpected ZIP order. Expected: {order}; actual: {actual}")

print("Created package.zip with the requested entry order.")

Each write() call follows order. The arcname argument controls the name stored in the archive independently of the source path. Python documents ZipFile.write() and namelist() in its zipfile documentation.

#1 Best Overall
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400) | Everyday HDD storage. Plug-and-play backup. Windows & macOS. Adobe CC trial included. 1-Year Warranty
  • Easily store and access 2TB to content on the go with the Seagate Portable Drive, a USB external hard drive
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.

Command-line alternatives

Python’s built-in command

python -m zipfile -c ordered-files.zip 
  01-introduction.pdf 
  02-installation.pdf 
  03-configuration.pdf 
  10-troubleshooting.pdf

python -m zipfile -l ordered-files.zip

The arguments are explicit, so their sequence is clear. Avoid relying on a wildcard such as * when order matters: shell expansion, locale, filesystem traversal, and the archiver can all affect the resulting list.

7-Zip

7z a -tzip ordered-files.zip 
  01-introduction.pdf 
  02-installation.pdf 
  03-configuration.pdf 
  10-troubleshooting.pdf

7z l ordered-files.zip

7-Zip supports ZIP creation and listing; its official documentation is at 7-zip.org and the download page. Do not treat -mqs as a general ZIP-order switch. The 7-Zip FAQ describes that sorting control for solid 7z archives, not ordinary ZIP entry sequencing: 7-Zip FAQ.

Appending with a shell loop

A manifest-driven loop can append entries in a controlled sequence:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
  • Easily store and access 5TB of content on the go with the Seagate portable drive, a USB external hard Drive
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.
rm -f ordered-files.zip

while IFS= read -r file; do
    [ -z "$file" ] && continue
    zip -q ordered-files.zip "$file"
done < order.txt

For production builds, a library that creates the archive once is safer than repeatedly editing it. Rebuilding also avoids accidental duplicate entries.

Use a manifest for repeatable builds

Store the authoritative sequence in order.txt:

01-introduction.pdf
02-installation.pdf
03-configuration.pdf
10-troubleshooting.pdf

Then validate every line before writing:

from pathlib import Path
from zipfile import ZipFile, ZIP_DEFLATED

root = Path("files")
manifest = Path("order.txt")
order = []
seen = set()

for line in manifest.read_text(encoding="utf-8").splitlines():
    name = line.strip()
    if not name or name.startswith("#"):
        continue
    if name in seen:
        raise ValueError(f"Duplicate archive name: {name}")
    source = root / name
    if not source.is_file():
        raise FileNotFoundError(source)
    seen.add(name)
    order.append(name)

with ZipFile("ordered-files.zip", "w", ZIP_DEFLATED) as zf:
    for name in order:
        zf.write(root / name, arcname=name)

A checked-in manifest makes changes reviewable and prevents accidental dependence on directory enumeration.

Directories, sorting, and duplicate names

Recursive directory scans

Filesystem traversal order is not a portable contract. If automatic order is acceptable, define it explicitly:

Rank #3
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
  • Easily store and access 1TB to content on the go with the Seagate Portable Drive, a USB external hard drive.Specific uses: Personal
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop. Reformatting may be required for Mac
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.
files = sorted(
    path for path in Path("package").rglob("*")
    if path.is_file()
)

Ordinary lexical sorting puts file-10.txt before file-2.txt. Zero-pad numbers or implement a natural-sort key. A manifest is usually clearer for release packages.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Directory entries

Some ZIPs contain explicit records such as docs/; others contain only paths such as docs/01-installation.pdf. Do not assume that every archive has separate directory records.

Duplicate archive names

ZIP permits duplicate member names. Appending the same name can create another entry rather than replace the first, producing tool-dependent extraction and lookup behavior. Create a fresh archive, reject duplicates, and compare the final names with the expected list.

Rank #4
Seagate Portable 4TB External Hard Drive HDD – USB 3.0, 1-Year Rescue | Everyday HDD storage. Plug-and-play backup. Windows & macOS. Adobe CC trial included. 1-Year Warranty
  • Easily store and access 4TB of content on the go with the Seagate Portable Drive, a USB external hard drive.Specific uses: Personal
  • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
  • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
  • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
  • The available storage capacity may vary.

Why a viewer may still show alphabetical order

A correct archive can appear sorted by name because the viewer chooses its own presentation. To diagnose this:

  1. List members programmatically with Python’s namelist(), or inspect with 7z l.
  2. Compare that sequence with the intended manifest.
  3. If humans must see the sequence in arbitrary software, use zero-padded names such as 01-, 02-, and 10-.

Numeric prefixes improve name-based sorting but do not guarantee extraction order or application behavior.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When ZIP order is not enough

Extraction programs may process central-directory entries, sort them, parallelize work, or create directories before files. An application that needs a workflow sequence should read explicit metadata instead:

Best Value
Sale
UnionSine 500GB Ultra Slim Portable External Hard Drive HDD-USB 3.0 | for PC, Mac, Laptop, PS4, Xbox one, Xbox 360-(Black)
  • [Upgraded Version] - This external hard drive features a mirrored logo stripe combined with a striped anti-slip design, and the rounded corners of the casing make it easier to grip. The stripes also have a heat dissipation function, ensuring stable and fast data transfer.
  • 【Ultra-thin and quiet】 - The motherboard adopts JMicron 578 noise-free solution, giving you a quiet working environment. Lightweight and portable size designed to fit in your pocket for easy portability.
  • 【Ultra-Fast Data Transfers】 - Pairing this external hard drive with JMicron 578 solution USB 3.0 and USB 2.0 interfaces enables blazing-fast data transfer. It boasts theoretical read speeds of up to 125MB/s and write speeds of up to 103MB/s.
  • 【Plug and Play】 - With no software to install, just plug it in and the drive is ready to use.The hard disk chip is wrapped with an aluminum anti-interference layer to increase heat dissipation and protect data.
  • 【What You Get】 - 1 x Portable Hard Drive, 1 x USB 3.0 Cable, 1 x User Manual, Gift-type shell packaging ,Three-year manufacturer's warranty and free technical support services.
{
  "files": [
    "01-introduction.pdf",
    "02-installation.pdf",
    "03-configuration.pdf"
  ]
}

Include a manifest, playlist, index, or instruction file in the package. ZIP itself does not define general application-level sequencing semantics; the format overview at p1k.se/appnote.md is useful background.

Common failure modes and fixes

“I passed files in order, but the file manager shows them alphabetically.”

The viewer is sorting its display. Verify the archive’s member list, then use padded names if visible order matters.

“Adding files later changed the order.”

Append/edit operations can add entries at the end or rewrite metadata. Recreate the archive from the complete authoritative list.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“The archive has the right files, but my script processes them differently.”

Check whether the script sorts names, converts them to an unordered collection, or assumes extraction order. Read the member list explicitly and use a manifest for required sequencing.

“The application ignores the order after extraction.”

That application treats the ZIP as an unordered collection. Change the package to include an index, or change the consumer to read it.

Quick Recap

Bestseller No. 1
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400) | Everyday HDD storage. Plug-and-play backup. Windows & macOS. Adobe CC trial included. 1-Year Warranty
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400) | Everyday HDD storage. Plug-and-play backup. Windows & macOS. Adobe CC trial included. 1-Year Warranty
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$129.99
Bestseller No. 2
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$219.99
Bestseller No. 3
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$119.80
Bestseller No. 4
Seagate Portable 4TB External Hard Drive HDD – USB 3.0, 1-Year Rescue | Everyday HDD storage. Plug-and-play backup. Windows & macOS. Adobe CC trial included. 1-Year Warranty
Seagate Portable 4TB External Hard Drive HDD – USB 3.0, 1-Year Rescue | Everyday HDD storage. Plug-and-play backup. Windows & macOS. Adobe CC trial included. 1-Year Warranty
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$189.99

Production checklist

  • Define the sequence in an explicit list or checked-in manifest.
  • Validate that every source file exists.
  • Reject duplicate archive names.
  • Create a new archive rather than relying on incremental edits.
  • List the generated members and compare them with the expected sequence.
  • Test with the exact viewer, extractor, or application that will consume the ZIP.
  • Use a manifest whenever order carries semantic meaning.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

7-Zipfile managementPythonsoftware packagingZIP files

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.