2013-02-20 99 views
0

我需要將來自不同位置的文件集合壓縮成一個zip文件,保持其初始關係。例如,我只需要在以下文件夾結構使用AntBuilder壓縮特定文件

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

A1和B2,我想zip文件看起來像:

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

我如何能做到用AntBuilder? 我已經試過:

高清deploymentFiles = [ 「$ HOME /歌/ a.tsv」, 「$ HOME /歌/ b.tsv」]

高清螞蟻=新AntBuilder ()

高清壓縮文件=新的文件( 「deployment_zipFile.zip」)

ant.zip(destFile: 「$ {zipFile.getAbsolutePath()}」){ 文件集(DIR: 「$ HOME」) {f - > 包括:deploymentFiles.join( 「」) } }}

但這只是拉鍊的整個主文件夾。

回答

1

在指定的目錄結構是這樣的:

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

然後,該代碼:

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(' ')) 

創建其中當提取包含一個zip文件:

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 
+1

@yossale奇數..經過測試,它似乎工作... – 2013-02-20 12:38:54

+0

對不起,我的壞!我拼錯了主目錄,所以找不到任何文件。 – Yossale 2013-02-20 12:43:39