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

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