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.2 KiB

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