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
我可能会尝试使用文件集将它们全部复制到另一个位置:
<project name="test" default="copy"> <target name="copy"> <mkdir dir="build"/> <copy todir="build"> <fileset dir="src" includes="File *.txt"/> </copy> </target> </project>
但include =将space(和逗号)视为分隔符,因此将其视为包含“File”和“* .txt” – 因此它实际上复制了每个文件.如果你想在一个模式中使用文字字符,并且阅读源代码,那么文档就没有提到如何逃避角色,似乎它们根本没有放入任何转义机制.
我们在构建中将此作为一个真正的问题,但我们只匹配一个文件,因此我只使用了一个变通方法< fileset file =“...”/>.
但是,一般情况下,文件的数量可能很大,或者您可能不希望每次更改文件时都更新构建,那么正确的方法是什么?
使用嵌套include的文件集:<fileset dir="src"> <include name="File *.txt"/> </fileset>
要包含的name参数是单个模式,因此不将空格视为分隔符.
精彩评论