如何将文件与Ant中的模式中的空格进行匹配?

Tre*_*kaz 4 ant fileset

给定一个像这样的源文件目录:

tester$ ls -l src
-rw-r--r--   1 tester  staff    0 24 Feb 11:28 File 1.txt
-rw-r--r--   1 tester  staff    0 24 Feb 11:28 File 2.txt
-rw-r--r--   1 tester  staff    0 24 Feb 11:28 File 3.txt
-rw-r--r--   1 tester  staff    0 24 Feb 11:30 FileFalse 1.txt
-rw-r--r--   1 tester  staff    0 24 Feb 11:30 FileFalse 2.txt
-rw-r--r--   1 tester  staff    0 24 Feb 11:30 FileFalse 3.txt
Run Code Online (Sandbox Code Playgroud)

我可能会尝试使用以下方法将它们全部复制到另一个位置fileset:

<project name="test" default="copy">
  <target name="copy">
    <mkdir dir="build"/>
    <copy todir="build">
      <fileset dir="src" includes="File *.txt"/>
    </copy>
  </target>
</project>
Run Code Online (Sandbox Code Playgroud)

但是include=将空格(和逗号)视为分隔符,因此将其视为包含"文件"和"*.txt" - 因此它实际上复制了每个文件.如果你想在一个模式中使用文字字符,并且阅读源代码,那么文档就没有提到如何逃避角色,似乎它们根本没有放入任何转义机制.

我们在构建中将此作为一个真正的问题,但我们只匹配一个文件,所以作为我刚才使用的解决方法<fileset file="..."/>.

但是,一般情况下,文件的数量可能很大,或者您可能不希望每次更改文件时都更新构建,那么正确的方法是什么?

gre*_*449 5

使用fileset嵌套的include:

<fileset dir="src">
  <include name="File *.txt"/>
</fileset>
Run Code Online (Sandbox Code Playgroud)

所述name参数include是一个单一的图案,使得空间不被作为分隔符处理.