• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ant: can't delete directory if it's not empty ?

 
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I've run into a problem when using Ant's < delete > task.
I'm getting the impression that if you use "delete" along with < fileset > and Selectors, it won't allow you to delete a directory unless it's empty...

Example:



I'm running it, and it seems to find my "temp" sub-directories, but it would only delete the empty ones. If a "temp" directory contains some files, it refuses to delete it (but doesn't issue any error messages).

Help would be appreciated.
Thanks.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I'm getting the impression that if you use "delete" along with < fileset > and Selectors, it won't allow you to delete a directory unless it's empty...


Nope. Ant will let you delete directories even if they are not empty. You say Ant "won't allow" the deletion of directories which contain files. Do you get a message from your OS stopping you, or does your target finish and the directories remain? If its the former, the OS will stop you deleting directories containing files that are being used. You probably wan't to check this is not the case. If its the latter, double-check your Selector. Is it actually matching anything? You can run Ant with -verbose flag to see how many directories this target matches.
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also got battered by Ant refusing to delete CVS directories. I believe that by ant 6.2 the rules have changed, but in some earlier versions there was an implicit exclusion list that you had to turn off or the infrastructure support directories (including the CVS dirs) wouldn't get deleted, so of course their containing directories couldn't be deleted either.

The standard exclusion list remains in Ant 6.2, but now if you use the "defaultexcludes" option it nags you.
 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Sturrock:
Nope. Ant will let you delete directories even if they are not empty. You say Ant "won't allow" the deletion of directories which contain files. Do you get a message from your OS stopping you, or does your target finish and the directories remain?



Thanks for your reply.
It's the latter - ant announces success, yet not all directories are deleted.
It's definitely an issue(or feature ?) of Ant, and not my directory structure...
I've tested the exact < delete > task quoted in my original question. Gave it a root directory with sub-dirs named "temp-1", "temp-2"...
It definitely deleted the empty ones, while the non-empty ones were letf intact. Strange but true...
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that the task you are testing? I've just cut-and-paste it and it deletes none of my subdirectories. And indeed it shouldn't, since you don't include the "includeEmptyDirs" attribute of the delete task, so emtpy directories will not be deleted according to the docs.

Re-reading the selector documentation I think your target is flawed anyway. If you use more than one selector (as you do), shouldn't you be combining them with the <and /> element?

Also, remember that Ant is just a Java application and Java is case-sensitive. So your target will only delete things which include the lower-case pattern "temp".

This is how I'd write this target:

This deletes all sub-directories of root which contain "temp", regardless of whether they include files or not.
 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Sturrock:
Re-reading the selector documentation I think your target is flawed anyway. If you use more than one selector (as you do), shouldn't you be combining them with the <and /> element?



Thanks very much for your reply.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic