转换一个Ant文件集到多个应用ARGS [英] Converting an Ant fileset to multiple apply args
问题描述
我有一些文件:
dir/foo.txt
dir/bar.txt
dir/foobar.txt
在一个Ant 适用
的任务,我想通过文件的列表作为参数:
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 不支持的文件集)的
(This example doesn't work because arg doesn't support fileset)
推荐答案
下面的说明使用 pathconvert 任务。
的转换路径使用传递给可执行文件&LT; ARG线/方式&gt;
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文件集到多个应用ARGS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!