Using regular expressions to select files when using ant copy task
Hi,
I have 'src' folder and a 'dest' folder. The 'src' folder has the following files:
1) ans_key.tif
2) arrow.tif
3) eqn_y=x+1.tif
4) re teach.tif
5) ab+cd.tif
I want to copy all files that conform to a naming convention to 'dest' folder. The rules are simple: only allowed characters in file names are a-z, A-Z, 0-9, dash(-), underscore(_) and period(.). Which means, I want only files 1 and 2 to be copied over to 'dest'. For this purpose, I wrote the following build.xml:
<project name="name of project" default="copy_graphics" basedir=".">
<target name="copy_graphics" description="Copy Graphics">
<copy overwrite="true" todir="dest">
<fileset dir="src" includes="**/*.tif">
<containsregexp expression="^[a-zA-Z0-9\._-]+$"/>
</fileset>
</copy>
</target>
</project>
But it didn't work. What's more confusing is except for file 2 (arrow.tif ), all others get copied.
I read in one of the forums that <containsregexp> looks in the content rather than the filename. So I tried playing around various combinations of:
<fileset dir="src">
<filename name="**/^[a-zA-Z0-9\._-]+\.tif$"/>
</fileset>
That didn't work either. Can anybody please help?
Thanks!