ANT Tags <copy/>, <filter/>

- Info:

- Copies one ore more files.

- If <filter> is used tokens inside files, like @name@, are replaced with real values before files are copied.

 

- CopyFile:

- Create ANT Script Test.xml

- Src.txt from current directory is copied as Dest.txt in current directory.

 

Test.xml

<?xml version="1.0" encoding="UTF-8"?>

<project name="MyAntProject" default="default" basedir=".">

<target name="default">

 

<copy file = "Src.txt"

tofile = "Dest.txt"

overwrite = "yes"/>

 

</target>

</project>

 

- CopyFiles:

- Create ANT Script Test.xml

- All files with extension .txt in current directory are copied to directory dest in current directory.

 

Test.xml

<?xml version="1.0" encoding="UTF-8"?>

<project name="MyAntProject" default="default" basedir=".">

<target name="default">

 

<copy todir = "dest">

<fileset dir = ".">

<include name = "**/*.txt"/>

</fileset>

</copy>

 

</target>

</project>

 

- ReplaceTokensAndCopyFile:

- Create ANT Script Test.xml

- Src.txt from current directory is copied as Dest.txt in current directory.

- All occurences of @name@ and @age@ in Src.txt are replaced with values John and 50 before Src.txt is copied as Dest.txt.

 

Test.xml

<?xml version="1.0" encoding="UTF-8"?>

<project name="MyAntProject" default="default" basedir=".">

<target name="default">

<filter token = "name" value="John"/>

<filter token = "age" value="50"/>

<copy file = "Src.txt"

tofile = "Dest.txt"

overwrite = "yes"

filtering = "true"/>

</target>

</project>

 

Src.txt

@name@ is @age@ years old.

Dest.txt

John is 50 years old.