💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# B.11 CopyTask 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 NameTypeDescriptionDefaultRequired`file``String`The source file.Yes聽`tofile``String`The destination the file is to be written to. `tofile` specifies a `full` filename. If you only want to specify a directory to copy to, use `todir`. Either this or the `todir` attribute is required. n/aYes (or `todir`)`todir``String`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 `tofile`. The directory must exist.n/aYes (or `tofile`)`overwrite``Boolean`Overwrite existing files even if the destination files are newer.`false`Notstamp or preservelastmodified`Boolean`If set to `true`, the new file will have the same mtime as the old one.`false`Nopreservemode or preservepermissions`Boolean`If set to `true`, the new file (and directory) will have the same permissions as the old one. The `mode` specified for directory creation will be ignored.`true`No`includeemptydirs``Boolean`If set to `true`, also empty directories are copied. `true`No`mode``Integer`Mode (octal) to create directories with.From umaskNo`haltonerror``Boolean`If set to `true`, halts the build when errors are encountered.`true`No`flatten``Boolean`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.`false`No`verbose``Boolean` Whether to print the list of the copied file. Defaults to false.`false`No ### Note No automatic expansion of symbolic links By default, `CopyTask` does not expand / dereference symbolic links, and will simply copy the link itself. To enable dereferencing, set `expandsymboliclinks` to `true` in the `<fileset>` tag. B.11.1 Examples On the one hand, CopyTask can be used to copy file by file: `<copy file="somefile.txt" tofile="/tmp/anotherfile.bak" overwrite="true"/>`Additionally, `CopyTask` supports Filesets, i.e. you can easily include/exclude one or more files. For more information, see [Appendix聽D](apd.html "Appendix D. Core Types") -- pay particular attention to the `defaultexcludes` attribute. [Appendix聽F](apf.html "Appendix F. Core mappers") and [Appendix聽E](ape.html "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> ``` B.11.2 Supported Nested Tags - `fileset` - `filelist` - `filterchain` - `mapper`