使用Ant遍历目录

Sha*_*rog 6 ant fileset

假设我有一组包含以下路径的PDF文件:

/some/path/pdfs/birds/duck.pdf
/some/path/pdfs/birds/goose.pdf
/some/path/pdfs/insects/fly.pdf
/some/path/pdfs/insects/mosquito.pdf
Run Code Online (Sandbox Code Playgroud)

我想做的是为每个PDF生成关于相对路径结构的缩略图,并输出到另一个位置,即:

/another/path/thumbnails/birds/duck.png
/another/path/thumbnails/birds/goose.png
/another/path/thumbnails/insects/fly.png
/another/path/thumbnails/insects/mosquito.png
Run Code Online (Sandbox Code Playgroud)

我希望这可以在Ant中完成.假设我将在命令行上使用Ghostscript并且我已经完成了对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>
Run Code Online (Sandbox Code Playgroud)

因此,我需要做的是制定出正确的价值观${thumbnail.image.path},并${input.pdf.path}在遍历PDF输入目录.

我可以访问ant-contrib(刚刚安装了"最新版本",即1.0b3),我正在使用Ant 1.8.0.我想我可以使用<for>任务,<fileset>s和<mapper>s 来做一些工作,但我无法将它们放在一起.

我尝试过类似的东西:

    <for param="file">
        <path>
            <fileset dir="${some.dir.path}/pdfs">
                <include name="**/*.pdf"/>
            </fileset>
        </path>
        <sequential>
            <echo message="@{file}"/>
        </sequential>
    </for>
Run Code Online (Sandbox Code Playgroud)

但不幸的@{file}是,该属性是一个绝对的路径,我找不到任何简单的方法将其分解为相关组件.

如果我只能使用自定义任务执行此操作,我想我可以编写一个,但我希望我可以将现有组件插入.

mar*_*ton 6

在顺序任务中,您可以使用ant-contrib propertyregex任务将输入路径映射到输出.例如:

<propertyregex override="yes" property="outfile" input="@{file}"
               regexp="/some/path/pdfs/(.*).pdf"
               replace="/another/path/\1.png" />
Run Code Online (Sandbox Code Playgroud)

哪款地图,例如/some/path/pdfs/birds/duck.pdf/another/path/birds/duck.png.