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.

move.html 8.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Language" content="en-us">
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>Move Task</title>
  20. </head>
  21. <body>
  22. <h2><a name="move">Move</a></h2>
  23. <h3>Description</h3>
  24. <p>Moves a file to a new file or directory, or collections of files to
  25. a new directory. By default, the
  26. destination file is overwritten if it already exists. When <var>overwrite</var> is
  27. turned off, then files are only moved if the source file is newer than
  28. the destination file, or when the destination file does not exist.</p>
  29. <p><a href="../CoreTypes/resources.html#collection">Resource
  30. Collection</a>s are used to select a group of files to move. Only
  31. file system based resource collections are supported, this includes <a
  32. href="../CoreTypes/fileset.html">fileset</a>s, <a
  33. href="../CoreTypes/filelist.html">filelist</a> and <a
  34. href="../using.html#path">path</a>. Prior to Ant 1.7 only
  35. <code>&lt;fileset&gt;</code> has been supported as a nested element.
  36. To use a resource collection, the <code>todir</code> attribute must be
  37. set.</p>
  38. <p><b>Since Ant 1.6.3</b>, the <i>file</i> attribute may be used to move
  39. (rename) an entire directory. If <i>tofile</i> denotes an existing file, or
  40. there is a directory by the same name in <i>todir</i>, the action will fail.
  41. </p>
  42. <h3>Parameters</h3>
  43. <table border="1" cellpadding="2" cellspacing="0">
  44. <tr>
  45. <td valign="top"><b>Attribute</b></td>
  46. <td valign="top"><b>Description</b></td>
  47. <td align="center" valign="top"><b>Required</b></td>
  48. </tr>
  49. <tr>
  50. <td valign="top">file</td>
  51. <td valign="top">the file or directory to move</td>
  52. <td valign="top" align="center">One of <var>file</var> or
  53. at least one nested resource collection element</td>
  54. </tr>
  55. <tr>
  56. <td valign="top">preservelastmodified</td>
  57. <td valign="top">Give the moved files the same last modified
  58. time as the original source files.
  59. (<em>Note</em>: Ignored on Java 1.1)</td>
  60. <td valign="top" align="center">No; defaults to false.</td>
  61. </tr>
  62. <tr>
  63. <td valign="top">tofile</td>
  64. <td valign="top">the file to move to</td>
  65. <td valign="top" align="center" rowspan="2">With the <var>file</var> attribute,
  66. either <var>tofile</var> or <var>todir</var> can be used. With nested filesets,
  67. if the fileset size is greater than 1 or if the only entry in the fileset is a
  68. directory or if the <var>file</var> attribute is already specified, only
  69. <var>todir</var> is allowed</td>
  70. </tr>
  71. <tr>
  72. <td valign="top">todir</td>
  73. <td valign="top">the directory to move to</td>
  74. </tr>
  75. <tr>
  76. <td valign="top">overwrite</td>
  77. <td valign="top">overwrite existing files even if the destination
  78. files are newer (default is &quot;true&quot;)</td>
  79. <td valign="top" align="center">No</td>
  80. </tr>
  81. <tr>
  82. <td valign="top">filtering</td>
  83. <td valign="top">indicates whether token filtering should take place during
  84. the move. See the <a href="filter.html">filter</a> task for a description of
  85. how filters work.</td>
  86. <td valign="top" align="center">No</td>
  87. </tr>
  88. <tr>
  89. <td valign="top">flatten</td>
  90. <td valign="top">ignore directory structure of source directory,
  91. copy all files into a single directory, specified by the <var>todir</var>
  92. attribute (default is &quot;false&quot;).Note that you can achieve the
  93. same effect by using a <a href="../CoreTypes/mapper.html#flatten-mapper">flatten mapper</a></td>
  94. <td valign="top" align="center">No</td>
  95. </tr>
  96. <tr>
  97. <td valign="top">includeEmptyDirs</td>
  98. <td valign="top">Copy empty directories included with the nested FileSet(s).
  99. Defaults to &quot;yes&quot;.</td>
  100. <td valign="top" align="center">No</td>
  101. </tr>
  102. <tr>
  103. <td valign="top">failonerror</td>
  104. <td valign="top">If false, log a warning message, but do not stop the
  105. build, when the file to copy does not exist or one of the nested
  106. filesets points to a directory that doesn't exist or an error occurs
  107. while moving.
  108. </td>
  109. <td valign="top" align="center">No; defaults to true.</td>
  110. </tr>
  111. <tr>
  112. <td valign="top">verbose</td>
  113. <td valign="top">Log the files that are being moved.</td>
  114. <td valign="top" align="center">No; defaults to false.</td>
  115. </tr>
  116. <tr>
  117. <td valign="top">encoding</td>
  118. <td valign="top">The encoding to assume when filter-copying the
  119. files. <em>since Ant 1.5</em>.</td>
  120. <td align="center">No - defaults to default JVM encoding</td>
  121. </tr>
  122. <tr>
  123. <td valign="top">outputencoding</td>
  124. <td valign="top">The encoding to use when writing the files.
  125. <em>since Ant 1.6</em>.</td>
  126. <td align="center">No - defaults to the value of the encoding
  127. attribute if given or the default JVM encoding otherwise.</td>
  128. </tr>
  129. <tr>
  130. <td valign="top">enablemultiplemapping</td>
  131. <td valign="top">
  132. If true the task will process to all the mappings for a
  133. given source path. If false the task will only process
  134. the first file or directory. This attribute is only relevant
  135. if there is a mapper subelement.
  136. <em>since Ant 1.6</em>.</td>
  137. <td align="center">No - defaults to false.</td>
  138. </tr>
  139. <tr>
  140. <td valign="top">granularity</td>
  141. <td valign="top">The number of milliseconds leeway to give before
  142. deciding a file is out of date. This is needed because not every
  143. file system supports tracking the last modified time to the
  144. millisecond level. Default is 0 milliseconds, or 2 seconds on DOS
  145. systems. This can also be useful if source and target files live
  146. on separate machines with clocks being out of sync. <em>since Ant
  147. 1.6</em>.</td>
  148. </tr>
  149. </table>
  150. <h3>Parameters specified as nested elements</h3>
  151. <h4>mapper</h4>
  152. <p>You can define file name transformations by using a nested <a
  153. href="../CoreTypes/mapper.html">mapper</a> element. The default mapper used by
  154. <code>&lt;move&gt;</code> is the <a
  155. href="../CoreTypes/mapper.html#identity-mapper">identity</a>.</p>
  156. <p>Note that the source name handed to the mapper depends on the
  157. resource collection you use. If you use <code>&lt;fileset&gt;</code>
  158. or any other collection that provides a base directory, the name
  159. passed to the mapper will be a relative filename, relative to the base
  160. directory. In any other case the absolute filename of the source will
  161. be used.</p>
  162. <h4>filterchain</h4>
  163. <p>The Move task supports nested <a href="../CoreTypes/filterchain.html">
  164. FilterChain</a>s.</p>
  165. <p>
  166. If <code>&lt;filterset&gt;</code> and <code>&lt;filterchain&gt;</code> elements are used inside the
  167. same <code>&lt;move&gt;</code> task, all <code>&lt;filterchain&gt;</code> elements are processed first
  168. followed by <code>&lt;filterset&gt;</code> elements.
  169. </p>
  170. <h3>Examples</h3>
  171. <p><b>Move a single file (rename a file)</b></p>
  172. <pre>
  173. &lt;move file=&quot;file.orig&quot; tofile=&quot;file.moved&quot;/&gt;
  174. </pre>
  175. <p><b>Move a single file to a directory</b></p>
  176. <pre>
  177. &lt;move file=&quot;file.orig&quot; todir=&quot;dir/to/move/to&quot;/&gt;
  178. </pre>
  179. <p><b>Move a directory to a new directory</b></p>
  180. <pre>
  181. &lt;move todir=&quot;new/dir/to/move/to&quot;&gt;
  182. &lt;fileset dir=&quot;src/dir&quot;/&gt;
  183. &lt;/move&gt;
  184. </pre>
  185. <i>or, since Ant 1.6.3:</i>
  186. <pre>
  187. &lt;move file=&quot;src/dir&quot; tofile=&quot;new/dir/to/move/to&quot;/&gt;
  188. </pre>
  189. <p><b>Move a set of files to a new directory</b></p>
  190. <pre>
  191. &lt;move todir=&quot;some/new/dir&quot;&gt;
  192. &lt;fileset dir=&quot;my/src/dir&quot;&gt;
  193. &lt;include name=&quot;**/*.jar&quot;/&gt;
  194. &lt;exclude name=&quot;**/ant.jar&quot;/&gt;
  195. &lt;/fileset&gt;
  196. &lt;/move&gt;
  197. </pre>
  198. <p><b>Move a list of files to a new directory</b></p>
  199. <pre>
  200. &lt;move todir=&quot;some/new/dir&quot;&gt;
  201. &lt;filelist dir=&quot;my/src/dir&quot;&gt;
  202. &lt;file name="file1.txt"/&gt;
  203. &lt;file name="file2.txt"/&gt;
  204. &lt;/filelist&gt;
  205. &lt;/move&gt;
  206. </pre>
  207. <p><b>Append <code>&quot;.bak&quot;</code> to the names of all files
  208. in a directory.</b></p>
  209. <pre>
  210. &lt;move todir=&quot;my/src/dir&quot; includeemptydirs=&quot;false&quot;&gt;
  211. &lt;fileset dir=&quot;my/src/dir&quot;&gt;
  212. &lt;exclude name=&quot;**/*.bak&quot;/&gt;
  213. &lt;/fileset&gt;
  214. &lt;mapper type=&quot;glob&quot; from=&quot;*&quot; to=&quot;*.bak&quot;/&gt;
  215. &lt;/move&gt;
  216. </pre>
  217. </body>
  218. </html>