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 6629107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:12:48+00:00 2026-05-25T22:12:48+00:00

I want to combine several zip files together using ANT, but I’ve got three

  • 0

I want to combine several zip files together using ANT, but I’ve got three restrictions that cause the standard techniques to fail:

  1. There are files (with known filenames) that I do not want included in the final archive.
  2. Some of the source archives contain files with the same name, but different capitalization.
  3. The machine that runs the script uses a case-insensitive filesystem.

To make my problem concrete, here’s an example source archive. I do not know the file names represented by a.txt and A.txt, but I do know the filename b.txt.

$ touch a.txt ; zip src.zip a.txt ; rm a.txt 
$ touch A.txt ; zip src.zip A.txt ; rm A.txt 
$ touch b.txt ; zip src.zip b.txt ; rm b.txt 
$ unzip -l src.zip 
Archive:  src.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
        0  09-23-11 11:35   a.txt
        0  09-23-11 11:35   A.txt
        0  09-23-11 11:36   b.txt
 --------                   -------
        0                   3 files

And here’s what I want: (everything from the original archive except b.txt)

$ ant
$ unzip -l expected.zip
Archive:  expected.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
        0  09-23-11 11:35   a.txt
        0  09-23-11 11:35   A.txt
 --------                   -------
        0                   2 files

The two techniques that I’ve found recommended on the internet are:

<target name="unzip-then-rezip">
    <!-- Either a.txt or A.txt is lost during unzip and
         does not appear in out.zip -->
    <delete dir="tmp"/>
    <delete file="out.zip"/>
    <mkdir dir="tmp"/>
    <unzip src="src.zip" dest="tmp"/>
    <zip destfile="out.zip" basedir="tmp" excludes="b.txt"/>
</target>

<target name="direct-zip">
    <!-- Have not found a way to exclude b.txt from out.zip -->
    <delete file="out.zip"/>
    <zip destfile="out.zip">
        <zipgroupfileset dir="." includes="*.zip" />
    </zip>
</target>

Using unzip-then-rezip, I loose either a.txt or A.txt because the underlying filesystem is case-insensitive and can not store both files. Using direct-zip seems like the right way to go, but I have yet to find a way to filter out the files I don’t want included.

I’m about to resort to creating my own ANT task to do the job, but I’d much rather use standard ANT tasks (or even ant-contrib), even if there’s a performance or readability penalty.

  • 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-05-25T22:12:49+00:00Added an answer on May 25, 2026 at 10:12 pm

    Have a look at Ant’s Resource Collections, especially things like restrict that allow you to filter files (and zip file contents etc.) in quite flexible ways.

    This snippet seems to what you want (on my machine at least – OSX):

    <project default="combine">
      <target name="combine">
        <delete file="expected.zip" />
    
        <zip destfile="expected.zip">
          <restrict>
            <zipfileset src="src.zip" />
            <not>
              <name name="b.txt" />
            </not>
          </restrict>
        </zip>
    
      </target>
    </project>
    

    The input file:

    $ unzip -l src.zip
    Archive:  src.zip
      Length     Date   Time    Name
     --------    ----   ----    ----
            0  09-24-11 00:55   a.txt
            0  09-24-11 00:55   A.txt
            0  09-24-11 00:55   b.txt
     --------                   -------
            0                   3 files
    

    The output file:

    $ unzip -l expected.zip
    Archive:  expected.zip
      Length     Date   Time    Name
     --------    ----   ----    ----
            0  09-24-11 00:55   A.txt
            0  09-24-11 00:55   a.txt
     --------                   -------
            0                   2 files
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a html out of several html files, but that's
I've got several complex deployment projects that I'd like to combine into a single
I want to do a select in MySql that combines several columns... something like
I want to combine three tables - date, lead and click - in a
I want to combine two array's, excluding duplicates. I am using a custom class:
I want to combine three sprites and display it as a single sprite. I
In a table I want to combine some of the columns, but not in
Using Firebird, I want to combine the results of two queries using UNION ALL,
I want to combine a textbox and several validator controls into 1 usercontrol. Is
I have zip file that I get that, when unzipped, has several subfolders each

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.