将 Ant 文件集转换为多个应用参数 [英] Converting an Ant fileset to multiple apply args
问题描述
我有一些文件:
dir/foo.txt
dir/bar.txt
dir/foobar.txt
在 Ant apply
任务中,我想将文件列表作为参数传递:
In an Ant apply
task, I want to pass the list of files as arguments:
<target name="atask">
<apply executable="${cmd}" parallel="false" verbose="true">
<arg value="-in"/>
<srcfile/>
<arg value="dir/foo.txt"/>
<arg value="dir/bar.txt"/>
<arg value="dir/foobar.txt"/>
<fileset dir="${list.dir}" includes="*.list"/>
</apply>
</target>
这很好用,但是如果我想使用文件集动态选择文件列表怎么办:
This works fine, but what if I want to pick the list of files dynamically, using a fileset:
<fileset dir="dir" includes="*.txt"/>
如何将此文件集转换为 arg
元素 - 每个文件一个?类似的东西:
How can I convert this fileset to arg
elements - one per file? Something like:
<arg>
<fileset dir="dir" includes="*.txt"/>
</arg>
代替
<arg value="dir/foo.txt"/>
<arg value="dir/bar.txt"/>
<arg value="dir/foobar.txt"/>
(此示例不起作用,因为 arg 不支持 fileset)
(This example doesn't work because arg doesn't support fileset)
推荐答案
这里有一个例子来说明 pathconvert 任务.
Here's an example illustrating the use of the pathconvert task.
使用
将转换后的路径传递给可执行文件.
The converted path is passed to the executable using <arg line />
.
这假定 *.txt
文件的路径中没有空格.
This assumes no spaces in the paths of your *.txt
files.
<target name="atask">
<fileset dir="dir" id="myTxts">
<include name="*.txt" />
</fileset>
<pathconvert property="cmdTxts" refid="myTxts" pathsep=" " />
<apply executable="${cmd}" parallel="false" verbose="true">
<arg value="-in" />
<srcfile />
<arg line="${cmdTxts}" />
<fileset dir="${list.dir}" includes="*.list" />
</apply>
</target>
如果您可能遇到空格,则应该这样做:如上所述,但将(希望哪几行很明显)更改为:
If you might encounter spaces this should do: as above, but change (hopefully obvious which lines) to:
<pathconvert property="cmdTxts" refid="myTxts" pathsep="' '" />
和
<arg line="'${cmdTxts}'"/>
这篇关于将 Ant 文件集转换为多个应用参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!