Copies files or directories. Files are only copied if the source file is newer than the destination file, or when the destination file does not exist. It is possible to explicitly overwrite existing files.
CopyTask does not allow self copying, i.e. copying a file to the
same name for security reasons.
Table B.13: Attributes
|The source file.||Yes|
The destination the file is to be written to.
Either this or the
|n/a||Yes (or |
|The directory the file is to be copied to. The file will have the
same name of the source file. If you want to specify a different name,
use ||n/a||Yes (or |
|Overwrite existing files even if the destination files are newer.||No|
|tstamp or preservelastmodified||If set to ||No|
|preservemode or preservepermissions||If set to ||No|
|If set to ||No|
|Mode (octal) to create directories with.||From umask||No|
|If set to ||No|
|Ignore the directory structure of the source files, and copy all files into the directory specified by the todir attribute. Note that you can achieve the same effect by using a flatten mapper.||No|
|Whether to print the list of the copied file. Defaults to false.||No|
No automatic expansion of symbolic links
CopyTask does not expand / dereference symbolic
links, and will simply copy the link itself. To enable dereferencing, set
true in the
On the one hand, CopyTask can be used to copy file by file:
<copy file="somefile.txt" tofile="/tmp/anotherfile.bak" overwrite="true"/>
CopyTask supports Filesets, i.e. you can easily
include/exclude one or more files. For more information, see Appendix D, Core Types -- pay particular attention to the
defaultexcludes attribute. Appendix F, Core mappers and Appendix E, Core filters are
also supported by
CopyTask, so you can do almost everything that
needs processing the content of the files or the filename.
<copy todir="/tmp/backup" > <fileset dir="."> <include name="**/*.txt" /> <include name="**/*.doc" /> <include name="**/*.swx" /> </fileset> <filelist dir="." files="test.html"/> </copy>
<copy todir="build" > <fileset defaultexcludes="false" expandsymboliclinks="true" dir="."> <include name="**/*.php" /> </fileset> </copy>