bearhunterUA bearhunterUA - 1 year ago 216
Groovy Question

Can not delete directory by mask in Gradle

I try to delete directory in 'foo/dir' with name 'public-someHash'. 'SomeHash' was created dynamically (eg 'dsflsdfn') and always new. I tried to use 'fileTree' but directory still present. There is my code:

tasks.create(name: 'delete', type : Delete) {
delete fileTree(dir: 'foo/dir/', include: 'public-*/**')

What is wrong with my mask?

UDP: I have similar task in Ant and all works fine:

<target name="delete">
<delete includeemptydirs="true">
<fileset dir="foo/dir/">
<include name="public-*/**"/>

Answer Source

EDIT: Apologies, as original answer was based on a misreading of the question.

Here's one way to do it, but not the most elegant:

task myDelete(type: Delete) {
    def files = new HashSet()

    new File('foo/dir').eachFile { file ->
        if (file.isDirectory() && ( ==~ /public-.*/)) {
            files << file

    delete files
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download