Thiago
Thiago

Reputation: 137

How can I add files in separate folders to a ZIP archive?

I am trying to add 3 diferent TXT files to one ZIP file. Those 3 TXT files are in separate folders but I have their path.

In the end, I just want a ZIP file with those 3 files in it.

Also, if one of them does not exist, will it include the 2 other ones or will it throw an exception and create no ZIP file?

Upvotes: 1

Views: 877

Answers (1)

jgritty
jgritty

Reputation: 11935

<zip destfile="your.zip">
    <fileset dir="path1" includes="file1.txt"/>
    <fileset dir="path2" includes="file2.txt"/>
    <fileset dir="path3" includes="file3.txt"/>
</zip>

You can include multiple filesets into a single zip file.

If the path doesn't exist, you'll get an error. If a file doesn't exist, it doesn't care. If none of the files exist, you'll get a warning.

Upvotes: 1

Related Questions