使用映射器和放大器;文件集文件复制到不同的子目录? [英] Using mapper & fileset to copy files into a different subdirectory?
问题描述
我要创建副本文件的目录使用相同的文件夹结构的目标目录,再加上多了一个子文件夹附加Ant目标。
I want to create an Ant target that copies files in a directory to a destination directory with the same folder structure, plus one more subfolder appended.
例如,源是:
a/b/c/foo.pdf
d/e/f/bar.pdf
我想目标是:
a/b/c/x/foo.pdf
d/e/f/x/foo.pdf
下面是我的目标,到目前为止,但它似乎没有被做任何事情:
Here is my target so far, but it doesn't appear to be doing anything:
<copy todir="${dest.dir}">
<fileset dir="${src.dir}" casesensitive="yes">
<include name="**${file.separator}foo.pdf" />
</fileset>
<mapper type="glob"
from="foo.pdf" to="x${file.separator}foo.pdf" />
</copy>
我是什么失踪?
推荐答案
您可以使用 正则表达式
映射:
You could use a regexp
mapper:
<copy todir="${dest.dir}">
<fileset dir="${src.dir}" casesensitive="yes">
<include name="**/*.pdf"/>
</fileset>
<mapper type="regexp" from="^(.*)/(.*\.pdf)" to="\1/x/\2" />
</copy>
我用硬codeD file.separators缩短。基本上,你分割路径输入文件(从)进入目录和文件名(捕获 \\ 1
和 \\ 2
),然后插入 \\ X
它们之间额外的元素(地)。
I've used hard-coded file.separators to shorten. Basically, you split the path to the input file (from) into directory and filename (capture \1
and \2
) and then insert the \x
extra element between them (to).
我不是你的例子清晰 - 它看起来像你想匹配bar.pdf并将其重命名为foo.pdf,以及改变的目录。如果你需要做到这一点,你可能会考虑链简单的正则表达式映射器的一对情侣,而不是试图编造一个复数之一:
I'm not clear on your example - it looks like you want to match 'bar.pdf' and rename it to 'foo.pdf', as well as changing the directory. If you need to do that, you might consider chaining a couple of simpler regexp mappers, rather than trying to cook up one complex one:
<copy todir="${dest.dir}">
<fileset dir="${src.dir}" casesensitive="yes">
<include name="**/*.pdf"/>
</fileset>
<chainedmapper>
<mapper type="regexp" from="^(.*)/(.*\.pdf)" to="\1/x/\2" />
<mapper type="regexp" from="^(.*)/(.*\.pdf)" to="\1/foo.pdf" />
</chainedmapper>
</copy>
在使用 水珠
一>映射器,你需要指定一个通配符 *
在从现场:
双方来往是必需的,
定义可以包含图案
最多一个*。对于每个源文件
从该模式,目标一致
文件名称将从构建
要通过替换在*模式
该图案与文字
从匹配模式中的*。
源文件名不匹配的
从格局将被忽略。
Both to and from are required and define patterns that may contain at most one *. For each source file that matches the from pattern, a target file name will be constructed from the to pattern by substituting the * in the to pattern with the text that matches the * in the from pattern. Source file names that don't match the from pattern will be ignored.
所以,这样的事情可能工作:
So something like this might work:
<mapper type="glob" from="*/foo.pdf" to="*/x/foo.pdf" />
这篇关于使用映射器和放大器;文件集文件复制到不同的子目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!