给定一个像这样的源文件目录:
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="..."/>
.
但是,一般情况下,文件的数量可能很大,或者您可能不希望每次更改文件时都更新构建,那么正确的方法是什么?
使用fileset
嵌套的include
:
<fileset dir="src">
<include name="File *.txt"/>
</fileset>
Run Code Online (Sandbox Code Playgroud)
所述name
参数include
是一个单一的图案,使得空间不被作为分隔符处理.
归档时间: |
|
查看次数: |
885 次 |
最近记录: |