Zip specific files with AntBuilder

て烟熏妆下的殇ゞ 提交于 2019-12-11 15:09:07

问题


I need to zip a collection of files from different location into one zip, keeping their initial relations. For example, I need only a1 and b2 from the following folder structure

Top -- A -- a1
         -- a2
    -- B -- b1
            b2

and i want the zip file to look like:

Top -- A -- a1
    -- B -- b2

How can I do that using AntBuilder? I've tried:

def deploymentFiles = [ "$HOME/Songs/a.tsv", "$HOME/Songs/b.tsv", ]

def ant = new AntBuilder()

def zipFile = new File("deployment_zipFile.zip")

ant.zip( destFile: "${zipFile.getAbsolutePath()}" ) { fileset( dir: "$HOME" ) { deploymentFiles.each {f -> includes: deploymentFiles.join(",") } } }

but this just zipped the entire HOME folder.


回答1:


Given a directory structure like this:

-- home
   |-- Songs
   |   |-- A
       |   |-- a1.tsv
       |   \-- a2.tsv
       |-- B
           |-- b1.tsv
           \-- b2.tsv

Then, this code:

def HOME = 'home'
def deploymentFiles = [ 'Songs/A/a1.tsv', 'Songs/B/b1.tsv' ]
def zipFile = new File("deployment_zipFile.zip")
new AntBuilder().zip( basedir: HOME,
                      destFile: zipFile.absolutePath,
                      includes: deploymentFiles.join( ' ' ) )

Creates a zip file which when extracted contains:

unzip ../deployment_zipFile.zip 
Archive:  ../deployment_zipFile.zip
   creating: Songs/
   creating: Songs/A/
  inflating: Songs/A/a1.tsv          
   creating: Songs/B/
  inflating: Songs/B/b1.tsv  


来源:https://stackoverflow.com/questions/14978846/zip-specific-files-with-antbuilder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!