”;
Description
Copy task copies a file/resource collection 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.
Properties
Sr.No | Attributes & Description |
---|---|
1 |
File
The file to copy. (Mandatory) |
2 |
Preservelastmodified
Give the copied files the same last modified time as the original source files. |
3 |
Tofile
The file to copy to. |
4 |
Todir
The directory to copy to. |
5 |
Overwrite
Overwrite existing files even if the destination files are newer. |
6 |
Force
Overwrite read-only destination files. |
7 |
Filtering
Indicates whether token filtering using the global build-file filters should take place during the copy. |
8 |
Flatten
Ignore the directory structure of the source files, and copy all files into the directory specified by the todir attribute. |
9 |
includeEmptyDirs
Copy any empty directories included in the FileSet(s). |
10 |
Failonerror
If false, log a warning message, but do not stop the build, when the file to copy does not exist or one of the nested filesets points to a directory that doesn”t exist or an error occurs while copying. |
11 |
Quiet
If true and failonerror is false, then do not log a warning message when the file to copy does not exist or one of the nested filesets points to a directory that doesn”t exist or an error occurs while copying. |
12 |
Verbose
Log the files that are being copied. |
13 |
Encoding
The encoding to assume when filter-copying the files. |
14 |
Outputencoding
The encoding to use when writing the files. |
15 |
Enablemultiplemappings
If true the task will process to all the mappings for a given source path. If false the task will only process the first file or directory. This attribute is only relevant if there is a mapper subelement. |
16 |
Granularity
The number of milliseconds leeway to give before deciding a file is out of date. This is needed because not every file system supports tracking the last modified time to the millisecond level. This can also be useful if source and target files live on separate machines with clocks being out of sync. |
Example
Usage
Create build.xml with the following content −
<?xml version="1.0"?> <project name="TutorialPoint" default="info"> <target name="info"> <copy file="text.txt" tofile="textcopy.txt"></copy> </target> </project>
Above script will copy a file say text.txt in the current directory as textcopy.txt.
Output
Running Ant on the above build file produces the following output −
F:tutorialspointant>ant Buildfile: F:tutorialspointantbuild.xml info: [echo] Copying 1 file to F:tutorialspointant BUILD SUCCESSFUL Total time: 1 second
”;