Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7923411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:19:02+00:00 2026-06-03T17:19:02+00:00

I have multiple zip files that have the same structure — they contain XML

  • 0

I have multiple zip files that have the same structure — they contain XML files at the root level. All files in each zip file are unique (no duplicates across the zip files). I need to combine all of the XML files from all of the zip files into a single zip file (with the same structure as the original zip files). Suggestions for how to best go about doing this? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T17:19:04+00:00Added an answer on June 3, 2026 at 5:19 pm

    This is the shortest version I could come up with:

    >>> import zipfile as z
    >>> z1 = z.ZipFile('z1.zip', 'a')
    >>> z2 = z.ZipFile('z2.zip', 'r')
    >>> z1.namelist()
    ['a.xml', 'b.xml']
    >>> z2.namelist()
    ['c.xml', 'd.xml']
    >>> [z1.writestr(t[0], t[1].read()) for t in ((n, z2.open(n)) for n in z2.namelist())]
    [None, None]
    >>> z1.namelist()
    ['a.xml', 'b.xml', 'c.xml', 'd.xml']
    >>> z1.close()
    

    Without testing the alternative, to me this is the best (and probably most obvious too!) solution because – assuming both zip files contains the same amount of data, this method requires the decompression and re-compression of only half of it (1 file).

    PS: List comprehension is there just to keep instructions on one line in the console (which speeds debugging up). Good pythonic code would require a proper for loop, given that the resulting list serves no purpose…

    HTH!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple URLs that returns zip files. Most of the files, I'm able
I have a big zipfile that I need to split in multiple zip files.
I have a standard Django Admin page that is used to upload multiple files.
I have a .zip file that contains sub-directories with html,png, and css files in
I have multiple forms on a page where each form will add individual item
I have multiple applications that share a config file that sets up NLog partially
I have multiple column headers that spans of multiple column and I would like
I have recently downloaded the FFmpeg-PHP extension (extracted from ffmpeg-php53-win32-vc9-all.zip) for PHP and I
I'm working on an app that will let users submit zip files that are
I have been making a program that creates multiple CSV's from another source CSV

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.