title: How to delete an empty directory (or the directory with all contents recursively) in gradle?
body: <p>I can't figure out how to delete all contents of a directory. </p>
  
  <p>For cleaning out a directory, I want to remove all files and directories inside it: I want to wipe everything there is inside (files and directories).</p>
  
  <p>I tried this with the delete task, but I can't figure out to make it also remove directories and not just files. I've tried different ways to specify the directories, but nothing works.</p>
  
  <pre><code>task deleteGraphicsAssets(type:Delete) {
      delete fileTree('src').include('**/*')
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>task deleteGraphicsAssets(type:Delete) {
      delete fileTree('src').include('/')
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>task deleteGraphicsAssets(type:Delete) {
      delete fileTree('src').include('*')
  }
  </code></pre>
  
  <p>Any help appreciated!</p>
  
  <hr>
  
  <p>Edit: </p>
  
  <p>This works - yet it seems a bit like a hack.</p>
  
  <pre><code>task deleteGraphicsAssets(type: Delete) {
      def dirName = "src"
      delete dirName
  
      doLast {
          file(dirName).mkdirs()
      }
  }
  </code></pre>
  
  <p>I was looking for something like:</p>
  
  <pre><code>task deleteGraphicsAssets(type: Delete) {
      deleteContentsOfDirectory "src"
  }
  </code></pre>
  
  <p>or </p>
  
  <pre><code>task deleteGraphicsAssets(type: Delete) {
      delete {dir : "src", keepRoot : true }
  }
  </code></pre>