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 9.2 KiB

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