通过与蚂蚁目录遍历 [英] Iterating through a directory with Ant
问题描述
让我们说我有PDF文件的集合,具有以下路径:
Let's say I have a collection of PDF files with the following paths:
/some/path/pdfs/birds/duck.pdf
/some/path/pdfs/birds/goose.pdf
/some/path/pdfs/insects/fly.pdf
/some/path/pdfs/insects/mosquito.pdf
我想要做的就是为每一个尊重的相对路径结构PDF,并输出到另一个位置,即缩略图:
What I'd like to do is generate thumbnails for each PDF that respect the relative path structure, and output to another location, i.e.:
/another/path/thumbnails/birds/duck.png
/another/path/thumbnails/birds/goose.png
/another/path/thumbnails/insects/fly.png
/another/path/thumbnails/insects/mosquito.png
我想这在Ant中完成。假设我要使用的Ghostscript在命令行上和我已经制定了调用GS:
I'd like this to be done in Ant. Assume I'm going to use Ghostscript on the command line and I've already worked out the call to GS:
<exec executable="${ghostscript.executable.name}">
<arg value="-q"/>
<arg value="-r72"/>
<arg value="-sDEVICE=png16m"/>
<arg value="-sOutputFile=${thumbnail.image.path}"/>
<arg value="${input.pdf.path}"/>
</exec>
所以我需要做的是为 $ {thumbnail.image.path}
和 $ {input.pdf制定出正确的价值观。路径}
在遍历PDF输入目录。
So what I need to do is work out the correct values for ${thumbnail.image.path}
and ${input.pdf.path}
while traversing the PDF input directory.
我有机会获得蚂蚁的contrib(刚刚安装了最新,这是1.0b3),我使用Ant 1.8.0。我想我可以使用&LT使一些工作;为&GT;
任务,&LT;文件集&GT;
和&LT;映射方式&gt;
S,但我无法把他们放在一起
I have access to ant-contrib (just installed the "latest", which is 1.0b3) and I'm using Ant 1.8.0. I think I can make something work using the <for>
task, <fileset>
s and <mapper>
s, but I am having trouble putting it all together.
我想是这样的:
<for param="file">
<path>
<fileset dir="${some.dir.path}/pdfs">
<include name="**/*.pdf"/>
</fileset>
</path>
<sequential>
<echo message="@{file}"/>
</sequential>
</for>
但不幸的是 @ {文件}
属性是一个绝对路径,我找不到分解成相对组件的任何简单的方法。
But unfortunately the @{file}
property is an absolute path, and I can't find any simple way of decomposing it into the relative components.
如果我只能做到这一点使用自定义任务,我想我可以写一个,但我希望我可以插在一起现有的组件。
If I can only do this using a custom task, I guess I could write one, but I'm hoping I can just plug together existing components.
推荐答案
在连续的任务,你可以也许能够使用的蚂蚁的contrib propertyregex 任务的输入路径输出映射。例如:
In the sequential task you could may be able to use the ant-contrib propertyregex task to map the input paths to output. For example:
<propertyregex override="yes" property="outfile" input="@{file}"
regexp="/some/path/pdfs/(.*).pdf"
replace="/another/path/\1.png" />
哪款地图,例如 /some/path/pdfs/birds/duck.pdf
到 /another/path/birds/duck.png
。
这篇关于通过与蚂蚁目录遍历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!