我需要将来自不同位置的文件集合压缩成一个zip,保持其初始关系。例如,我只需要来自以下文件夹结构的a1和b2
Top -- A -- a1
-- a2
-- B -- b1
b2
我希望zip文件看起来像:
Top -- A -- a1
-- B -- b2
我怎样才能使用AntBuilder? 我试过了:
def deploymentFiles = [ “$ HOME /歌/ 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 - > 包括:deploymentFiles.join(“,”) } }}
但这只是压缩了整个HOME文件夹。
答案 0 :(得分: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