title: Delete all files and sub directories but keep main directory
body: <p>I have a folder whose entire entire contents I want to delete, but I want to keep the actual folder. I have tried this:</p>
  
  <pre><code>function deleteFiles {
    # The parameter. 
    param([string]$sourceDir) 
  
    # Move the files
    Get-ChildItem -Path $sourceDir -Include *.* -Recurse | foreach { $_.Delete()}
  
    #Delete empty directories
    Get-ChildItem -Path $sourceDir -recurse | Where-Object {
      $_.PSIsContainer -eq $true -and (Get-ChildItem -Path $_.FullName) -eq $null
    } | Remove-Item 
  }
  </code></pre>
  
  <p>However as one of the subdirectories has its own sub directories they aren't deleted.</p>