You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

copy.html 4.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Ant User Manual</title>
  5. </head>
  6. <body>
  7. <h2><a name="copy">Copy</a></h2>
  8. <h3>Description</h3>
  9. <p>Copies a file or Fileset to a new file or directory. Files are
  10. only copied if the source file is newer than the destination file,
  11. or when the destination file does not exist. However, you can explicitly
  12. overwrite files with the <var>overwrite</var> attribute.</p>
  13. <p><a href="../CoreTypes/fileset.html">FileSet</a>s are used to select files to copy.
  14. To use a fileset, the <var>todir</var> attribute must be set.</p>
  15. <h3>Parameters</h3>
  16. <table border="1" cellpadding="2" cellspacing="0">
  17. <tr>
  18. <td valign="top"><b>Attribute</b></td>
  19. <td valign="top"><b>Description</b></td>
  20. <td align="center" valign="top"><b>Required</b></td>
  21. </tr>
  22. <tr>
  23. <td valign="top">file</td>
  24. <td valign="top">The file to copy.</td>
  25. <td valign="top" align="center">One of either <var>file</var> or
  26. at least one nested fileset element.</td>
  27. </tr>
  28. <tr>
  29. <td valign="top">preservelastmodified</td>
  30. <td valign="top">Give the copied files the same last modified
  31. time as the original files. Defaults to &quot;no&quot;.</td>
  32. <td valign="top" align="center">No</td>
  33. </tr>
  34. <tr>
  35. <td valign="top">tofile</td>
  36. <td valign="top">The file to copy to.</td>
  37. <td valign="top" align="center" rowspan="2">With the <var>file</var> attribute,
  38. either <var>tofile</var> or <var>todir</var> can be used. With nested filesets,
  39. only <var>todir</var> is allowed.</td>
  40. </tr>
  41. <tr>
  42. <td valign="top">todir</td>
  43. <td valign="top">The directory to copy to.</td>
  44. </tr>
  45. <tr>
  46. <td valign="top">overwrite</td>
  47. <td valign="top">Overwrite existing files even if the destination
  48. files are newer. Defaults to &quot;no&quot;.</td>
  49. <td valign="top" align="center">No</td>
  50. </tr>
  51. <tr>
  52. <td valign="top">filtering</td>
  53. <td valign="top">Indicates whether token filtering should take place during
  54. the copy. Defaults to &quot;no&quot;.</td>
  55. <td valign="top" align="center">No</td>
  56. </tr>
  57. <tr>
  58. <td valign="top">flatten</td>
  59. <td valign="top">Ignore directory structure of source directory,
  60. copy all files into a single directory, specified by the <var>todir</var>
  61. attribute. Defaults to &quot;no&quot;. Note that you can achieve the
  62. same effect by using a <a href="../CoreTypes/mapper.html#flatten-mapper">flatten mapper</a></td>
  63. <td valign="top" align="center">No</td>
  64. </tr>
  65. <tr>
  66. <td valign="top">includeEmptyDirs</td>
  67. <td valign="top">Copy empty directories included with the nested FileSet(s).
  68. Defaults to &quot;yes&quot;.</td>
  69. <td valign="top" align="center">No</td>
  70. </tr>
  71. </table>
  72. <h3>Parameters specified as nested elements</h3>
  73. <h4>mapper</h4>
  74. <p>You can define file name transformations by using a nested <a
  75. href="../CoreTypes/mapper.html">mapper</a> element. The default mapper used by
  76. <code>&lt;copy&gt;</code> is the <a
  77. href="../CoreTypes/mapper.html#identity-mapper">identity</a>.</p>
  78. <h3>Examples</h3>
  79. <p><b>Copy a single file</b></p>
  80. <pre>
  81. &lt;copy file=&quot;myfile.txt&quot; tofile=&quot;mycopy.txt&quot;/&gt;
  82. </pre>
  83. <p><b>Copy a file to a directory</b></p>
  84. <pre>
  85. &lt;copy file=&quot;myfile.txt&quot; todir=&quot;../some/dir/tree&quot;/&gt;
  86. </pre>
  87. <p><b>Copy a directory to another directory</b></p>
  88. <pre>
  89. &lt;copy todir=&quot;../new/dir&quot;&gt;
  90. &lt;fileset dir=&quot;src_dir&quot;/&gt;
  91. &lt;/copy&gt;
  92. </pre>
  93. <p><b>Copy a set of files to a directory</b></p>
  94. <pre>
  95. &lt;copy todir=&quot;../dest/dir&quot; &gt;
  96. &lt;fileset dir=&quot;src_dir&quot &gt;
  97. &lt;exclude name=&quot;**/*.java&quot;/&gt;
  98. &lt;/fileset&gt;
  99. &lt;/copy&gt;
  100. &lt;copy todir=&quot;../dest/dir&quot; &gt;
  101. &lt;fileset dir=&quot;src_dir&quot excludes=&quot;**/*.java&quot;/&gt;
  102. &lt;/copy&gt;
  103. </pre>
  104. <p><b>Copy a set of files to a directory appending
  105. &quot;<code>.bak</code>&quot; to the file name on the fly</b></p>
  106. <pre>
  107. &lt;copy todir=&quot;../backup/dir&quot; &gt;
  108. &lt;fileset dir=&quot;src_dir&quot /&gt;
  109. &lt;mapper type=&quot;glob&quot; from=&quot;*&quot; to=&quot;*.bak&quot;/&gt;
  110. &lt;/copy&gt;
  111. </pre>
  112. <hr><p align="center">Copyright &copy; 2000,2001 Apache Software Foundation. All rights
  113. Reserved.</p>
  114. </body>
  115. </html>