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.

delete.html 8.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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>Delete Task</title>
  20. </head>
  21. <body>
  22. <h2><a name="delete">Delete</a></h2>
  23. <h3>Description</h3>
  24. <p>Deletes a single file, a specified directory and all its files and
  25. subdirectories, or a set of files specified by one or more
  26. <a href="../CoreTypes/resources.html#collection">resource collection</a>s.
  27. The literal implication of <code>&lt;fileset&gt;</code> is that
  28. directories are not included; however the removal of empty directories can
  29. be triggered when using nested filesets by setting the
  30. <code>includeEmptyDirs</code> attribute to <i>true</i>. Note that this
  31. attribute is meaningless in the context of any of the various resource
  32. collection types that <i>do</i> include directories, but that no attempt
  33. will be made to delete non-empty directories in any case. Whether a
  34. directory is empty or not is decided by looking into the filesystem -
  35. include or exclude patterns don't apply here.</p>
  36. <p>
  37. If you use this task to delete temporary files created by editors
  38. and it doesn't seem to work, read up on the
  39. <a href="../dirtasks.html#defaultexcludes">default exclusion set</a>
  40. in <strong>Directory-based Tasks</strong>, and see the
  41. <code>defaultexcludes</code> attribute below.
  42. <p>For historical reasons <code>&lt;delete dir="x"/&gt;</code> is
  43. different from <code>&lt;delete&gt;&lt;fileset
  44. dir="x"/&gt;&lt;/delete&gt;</code>, it will try to remove everything
  45. inside "x" including "x" itself, not taking default excludes into
  46. account, blindly following all symbolic links. If you need more
  47. control, use a nested <code>&lt;fileset&gt;</code>.</p>
  48. <h3>Parameters</h3>
  49. <table border="1" cellpadding="2" cellspacing="0">
  50. <tr>
  51. <td valign="top"><b>Attribute</b></td>
  52. <td valign="top"><b>Description</b></td>
  53. <td align="center" valign="top"><b>Required</b></td>
  54. </tr>
  55. <tr>
  56. <td valign="top">file</td>
  57. <td valign="top">The file to delete, specified as either the simple
  58. filename (if the file exists in the current base directory), a
  59. relative-path filename, or a full-path filename.</td>
  60. <td align="center" valign="middle" rowspan="2">At least one of the two,
  61. unless nested resource collections are specified
  62. </tr>
  63. <tr>
  64. <td valign="top">dir</td>
  65. <td valign="top">The directory to delete, including all its files and
  66. subdirectories.<br>
  67. <b>Note:</b> <code>dir</code> is <em>not</em> used
  68. to specify a directory name for <code>file</code>; <code>file</code>
  69. and <code>dir</code> are independent of each other.<br>
  70. <b>WARNING:</b> Do <b>not</b> set <code>dir</code> to
  71. <code>&quot;.&quot;</code>, <code>&quot;${basedir}&quot;</code>,
  72. or the full-pathname equivalent unless you truly <em>intend</em> to
  73. recursively remove the entire contents of the current base directory
  74. (and the base directory itself, if different from the current working
  75. directory).</td>
  76. </tr>
  77. <tr>
  78. <td valign="top">verbose</td>
  79. <td valign="top">Whether to show the name of each deleted file.</td>
  80. <td align="center" valign="top">No, default &quot;false&quot;</i></td>
  81. </tr>
  82. <tr>
  83. <td valign="top">quiet</td>
  84. <td valign="top">If the specified file or directory does not exist,
  85. do not display a diagnostic message (unless Ant
  86. has been invoked with the <code>-verbose</code> or
  87. <code>-debug</code> switches) or modify the exit status to
  88. reflect an error.
  89. When set to &quot;true&quot;, if a file or directory cannot be deleted,
  90. no error is reported. This setting emulates the
  91. <code>-f</code> option to the Unix <em>rm</em> command.
  92. Setting this to &quot;true&quot; implies setting
  93. <code>failonerror</code> to &quot;false&quot;.
  94. </td>
  95. <td align="center" valign="top">No, default &quot;false&quot;</td>
  96. </tr>
  97. <tr>
  98. <td valign="top">failonerror</td>
  99. <td valign="top">Controls whether an error (such as a failure to
  100. delete a file) stops the build or is merely reported to the screen.
  101. Only relevant if <code>quiet</code> is &quot;false&quot;.</td>
  102. <td align="center" valign="top">No, default &quot;true&quot;</td>
  103. </tr>
  104. <tr>
  105. <td valign="top">includeemptydirs</td>
  106. <td valign="top">Whether to delete empty directories
  107. when using filesets.</td>
  108. <td align="center" valign="top">No, default &quot;false&quot;</td>
  109. </tr>
  110. <tr>
  111. <td valign="top">includes</td>
  112. <td valign="top"><em>Deprecated.</em> Use resource collections.
  113. Comma- or space-separated list of patterns of
  114. files that must be deleted. All files are relative to the directory
  115. specified in <code>dir</code>.</td>
  116. <td valign="top" align="center">No</td>
  117. </tr>
  118. <tr>
  119. <td valign="top">includesfile</td>
  120. <td valign="top"><em>Deprecated.</em> Use resource collections.
  121. The name of a file. Each line of
  122. this file is taken to be an include pattern.</td>
  123. <td valign="top" align="center">No</td>
  124. </tr>
  125. <tr>
  126. <td valign="top">excludes</td>
  127. <td valign="top"><em>Deprecated.</em> Use resource collections.
  128. Comma- or space-separated list of patterns of
  129. files that must be excluded from the deletion list.
  130. All files are relative to the directory specified in <code>dir</code>.
  131. No files (except default excludes) are excluded when omitted.</td>
  132. <td valign="top" align="center">No</td>
  133. </tr>
  134. <tr>
  135. <td valign="top">excludesfile</td>
  136. <td valign="top"><em>Deprecated.</em> Use resource collections.
  137. The name of a file. Each line of
  138. this file is taken to be an exclude pattern</td>
  139. <td valign="top" align="center">No</td>
  140. </tr>
  141. <tr>
  142. <td valign="top">defaultexcludes</td>
  143. <td valign="top"><em>Deprecated.</em> Use resource collections.
  144. Whether to use <a href="../dirtasks.html#defaultexcludes">
  145. default excludes.</a></td>
  146. <td align="center" valign="top">No, default &quot;true&quot;</td>
  147. </tr>
  148. <tr>
  149. <td valign="top">deleteonexit</td>
  150. <td valign="top">
  151. Indicates whether to use File#deleteOnExit() if there is a
  152. failure to delete a file, this causes the jvm to attempt
  153. to delete the file when the jvm process is terminating.
  154. <em>Since Ant 1.6.2</em></td>
  155. <td align="center" valign="top">No, default &quot;false&quot;</td>
  156. </tr>
  157. <tr>
  158. <td valign="top">removeNotFollowedSymlinks</td>
  159. <td valign="top">
  160. Whether symbolic links (not the files/directories they link to)
  161. should be removed if they haven't been followed because
  162. followSymlinks was false or the maximum number of symbolic links
  163. was too big.
  164. <em>Since Ant 1.8.0</em></td>
  165. <td align="center" valign="top">No, default &quot;false&quot;</td>
  166. </tr>
  167. </table>
  168. <h3>Examples</h3>
  169. <pre> &lt;delete file=&quot;/lib/ant.jar&quot;/&gt;</pre>
  170. <p>deletes the file <code>/lib/ant.jar</code>.</p>
  171. <pre> &lt;delete dir=&quot;lib&quot;/&gt;</pre>
  172. <p>deletes the <code>lib</code> directory, including all files
  173. and subdirectories of <code>lib</code>.</p>
  174. <pre> &lt;delete&gt;
  175. &lt;fileset dir=&quot;.&quot; includes=&quot;**/*.bak&quot;/&gt;
  176. &lt;/delete&gt;
  177. </pre>
  178. <p>deletes all files with the extension <code>.bak</code> from the current directory
  179. and any subdirectories.</p>
  180. <pre> &lt;delete includeEmptyDirs=&quot;true&quot;&gt;
  181. &lt;fileset dir=&quot;build&quot;/&gt;
  182. &lt;/delete&gt;
  183. </pre>
  184. <p>deletes all files and subdirectories of <code>build</code>, including
  185. <code>build</code> itself.</p>
  186. <pre> &lt;delete includeemptydirs=&quot;true&quot;&gt;
  187. &lt;fileset dir=&quot;build&quot; includes=&quot;**/*&quot;/&gt;
  188. &lt;/delete&gt;
  189. </pre>
  190. <p>deletes all files and subdirectories of <code>build</code>, without
  191. <code>build</code> itself.</p>
  192. <pre> &lt;delete includeemptydirs=&quot;true&quot;&gt;
  193. &lt;fileset dir=&quot;src&quot; includes=&quot;**/.svn&quot; defaultexcludes=&quot;false&quot;/&gt;
  194. &lt;/delete&gt;
  195. </pre>
  196. <p>deletes the subversion metadata directories under <code>src</code>. Because <code>.svn</code>
  197. is on of the <a href="../dirtasks.html#defaultexcludes">default excludes</a> you have to use the
  198. <code>defaultexcludes</code> flag, otherwise Ant wont delete these directories and the files in it.</p>
  199. </body>
  200. </html>