问题
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>
How do I specify an embedded comma?
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.
回答1:
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>
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
<delete dir="." includes="**/*.txt" />
<!-- call clean target from build2.xml -->
<ant file="./subdir/build2.xml" target="clean"/>
maindir/subdir/build2.xml
<delete dir="." includes="**/*.txt" />
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.
回答2:
Unless you have other files with names that end in cover that you don't want to delete, just leave the comma out:
<fileset dir="." includes="**/*cover"></fileset>
If you do have other files that end in cover that you don't want deleted, try the backslash suggestion from MattDMo's comment. You may have to double-backslash it ("**/*\\,cover
").
Another possibility: Can you configure Coverage to put its output in another directory, so you can just delete the whole directory? Or can you configure it to use a different output filename so you don't have this problem? I'm not familiar with Coverage, but looking at the link you provided, it looks like the data_file option might do one or both of those things.
来源:https://stackoverflow.com/questions/15419471/in-ant-how-do-i-specify-files-with-comma-in-filename