Reputation: 691
For a fileset like this:
XXX_staging
A_filename\A_filename.txt
B_filenAme\B_filenAme.txt
XXX_AL_staging
The following ant target will copy only the files whose names start with an uppercase "A", from the XXX_staging folder to the XXX_AL_staging folder:
<target name="split_topics">
<copy todir="XXX_AL_staging\" verbose="true" overwrite="true">
<fileset dir=".\XXX_staging" includes="**/A*.txt">
</fileset>
</copy>
</target>
What I want to do is copy only files whose names start with A through L. This doesn't work:
<target name="split_topics">
<copy todir="XXX_AL_staging\" verbose="true" overwrite="true">
<fileset dir=".\XXX_staging" includes="**/[A-L]*.txt">
</fileset>
</copy>
</target>
I'm wondering if the problem is that the second is not just a wildcard match like the first, but a regular expression match, which won't work for a filename? I don't want to match the contents of the files, just the filenames, so containsregexp seems to be out.
How do I do this?
Upvotes: 2
Views: 3130
Reputation: 77971
Filename selectors can utilize a regular expression.
├── build.xml
├── src
│ └── somedir
│ ├── A_filename.txt
│ ├── B_filename.txt
│ ├── C_filename.txt
│ ├── D_filename.txt
│ ├── E_filename.txt
│ ├── F_filename.txt
│ └── G_filename.txt
└── target
└── somedir
├── A_filename.txt
├── B_filename.txt
├── C_filename.txt
└── D_filename.txt
<project name="demo" default="copy">
<property name="src.dir" location="src"/>
<property name="build.dir" location="target"/>
<target name="copy">
<copy todir="${build.dir}" overwrite="true" verbose="true">
<fileset dir="${src.dir}">
<filename regex="\/[A-D].*.txt$"/>
</fileset>
</copy>
</target>
</project>
Upvotes: 4
Reputation: 100050
Unfortunately, ant patterns are not regular expressions, not even a little. They are wildcards with a very limited syntax. For a complex solution, you can use the ability to define your own task in Javascript and code something out, but this will not let you create an alternative file set pattern matching syntax.
Upvotes: 0