在 Ant 中,如何在文件名中指定带逗号的文件? [英] In Ant, how do I specify files with comma in filename?
问题描述
这是我尝试过的示例目标.事实证明,它想删除所有内容,因为逗号分隔了**/*"和cover"——可以理解.
Here is an example-target that I tried. Turns out, it wants to delete everything because the comma separates "**/*" and "cover" -- understandable.
<target name="clean">
<delete
verbose="true">
<fileset dir="." includes="**/*.pyo"></fileset>
<fileset dir="." includes="**/*,cover"></fileset>
</delete>
</target>
如何指定嵌入的逗号?
我正在尝试学习 Ant,这样我就不必为不同的操作系统维护不同的构建系统.在这种情况下,它在 Python 环境中,其中 *,cover 文件由名为 Coverage 的代码覆盖率检查工具创建.
I'm trying to learn Ant so I won't have to maintain different build-systems for different operating-systems. In this case, it's in a Python environment, where *,cover files are created by a code-coverage checking tool called Coverage.
推荐答案
你不需要逃避这个.只需使用
而不是 includes
参数.试试这个:
You don't need to escape this. Just use <include/>
instead of includes
arg. Try this:
<project name="test" default="clean">
<dirname property="build.dir" file="${ant.file.test}" />
<target name="clean">
<delete>
<fileset dir="${build.dir}/test">
<include name="**/*,*.xml" />
</fileset>
</delete>
</target>
</project>
顺便说一下.您不应该在 dir
参数中使用 .
(点).如果你想删除你有 build.xml
文件的目录中的文件,你应该传递绝对路径(为此你可以使用 <dirname/>
像我的例子).如果您将使用 .
那么您将遇到嵌套构建的问题.让我们想象一下,你有两个删除文件的构建,但第一个构建也调用了第二个构建:
By the way. You shouldn't use .
(dot) in you dir
argument. If you want to delete files in directory where you have got build.xml
file you should pass absolute path (to do this you can use <dirname/>
like in my example). If you will use .
then you will have problems with nested build. Let's imageine that you have got two builds which delete files but first build also call second build:
maindir/build1.xml
maindir/build1.xml
<delete dir="." includes="**/*.txt" />
<!-- call clean target from build2.xml -->
<ant file="./subdir/build2.xml" target="clean"/>
maindir/subdir/build2.xml
maindir/subdir/build2.xml
<delete dir="." includes="**/*.txt" />
在这种情况下,build2.xml 不会删除 subdir 中的 *.txt 文件,而是删除 maindir 中的 *.txt 文件,因为 ant 属性将传递给 build2.xml.当然,您可以使用 inheritAll="false"
来省略这一点,但根据我的经验,我知道在路径中使用 .
会给您带来很多问题.
In this case build2.xml won't delete *.txt files in subdir but *.txt files in maindir because ant properties will be passed to build2.xml. Of course you can use inheritAll="false"
to omit this but from my experience I know that using .
in paths will bring you a lot of problems.
这篇关于在 Ant 中,如何在文件名中指定带逗号的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!