Copies a file or Fileset to a new file or directory. Files are only copied if the source file is newer than the destination file, or when the destination file does not exist. However, you can explicitly overwrite files with the overwrite attribute.
FileSets are used to select files to copy. To use a fileset, the todir attribute must be set.
Attribute | Description | Required |
file | The file to copy. | One of either file or at least one nested fileset element. |
preservelastmodified | Give the copied files the same last modified time as the original source files. Defaults to "no". [ignored on Java 1.1] | No |
tofile | The file to copy to. | With the file attribute, either tofile or todir can be used. With nested filesets, if the fileset size is greater than 1 or if the only entry in the fileset is a directory or if the file attribute is already specified, only todir is allowed |
todir | The directory to copy to. | |
overwrite | Overwrite existing files even if the destination files are newer. Defaults to "no". | No |
filtering | Indicates whether token filtering using the global build file filters should take place during the copy. Defaults to "no". Nested filtersets will be used even if this value is "no" | No |
flatten | Ignore directory structure of source directory, copy all files into a single directory, specified by the todir attribute. Defaults to "no". Note that you can achieve the same effect by using a flatten mapper | No |
includeEmptyDirs | Copy empty directories included with the nested FileSet(s). Defaults to "yes". | No |
FileSets are used to select files to copy. To use a fileset, the todir attribute must be set.
You can define file name transformations by using a nested mapper element. The default mapper used by
<copy>
is the identity.
Filtersets are used to replace tokens in files that are copied. To use a filterset just add the nested filterset elements.
Copy a single file
<copy file="myfile.txt" tofile="mycopy.txt"/>
Copy a file to a directory
<copy file="myfile.txt" todir="../some/dir/tree"/>
Copy a directory to another directory
<copy todir="../new/dir"> <fileset dir="src_dir"/> </copy>
Copy a set of files to a directory
<copy todir="../dest/dir" > <fileset dir="src_dir" > <exclude name="**/*.java"/> </fileset> </copy> <copy todir="../dest/dir" > <fileset dir="src_dir" excludes="**/*.java"/> </copy>
Copy a set of files to a directory appending
".bak
" to the file name on the fly
<copy todir="../backup/dir" > <fileset dir="src_dir" /> <mapper type="glob" from="*" to="*.bak"/> </copy>
Copy a set of files to a replacing @TITLE@ with Foo Bar in all files.
<copy todir="../backup/dir" > <fileset dir="src_dir" /> <filterset> <filter token="TITLE" value="Foo Bar" /> </filterset> </copy>
Unix Note: file permissions are not retained when files are copied; they end up with the default UMASK permissions instead. This is caused by the lack of any means to query or set file permissions in the current Java runtimes. If you need a permission preserving copy function, use <exec executable="cp" ... > instead.
Copyright © 2001 Apache Software Foundation. All rights Reserved.