4

给定一个源文件目录,如下所示:

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

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

<project name="test" default="copy">
  <target name="copy">
    <mkdir dir="build"/>
    <copy todir="build">
      <fileset dir="src" includes="File *.txt"/>
    </copy>
  </target>
</project>

但是include=将空格(和逗号)视为分隔符,因此这被视为包括“文件”和“* .txt” - 因此它实际上复制了每个文件。文档没有提到如果您想在模式中使用文字字符,您将如何转义该字符,并且阅读源代码,似乎他们根本没有放入任何转义机制。

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

但是,一般来说,文件的数量可能很大,或者您可能不想在每次文件更改时更新构建,那么正确的方法是什么?

4

1 回答 1

5

使用fileset带有嵌套的include

<fileset dir="src">
  <include name="File *.txt"/>
</fileset>

to的name参数include是单个模式,因此空格不被视为分隔符。

于 2015-02-24T08:31:08.220 回答