title: Powershell command to delete subfolders without deleting the root
body: <p>I'm having problems to create a PS command that allows me to delete several subfolders without deleting the roof folder.</p>
  
  <p>I.E:</p>
  
  <p>C:\Test has many subfolders:</p>
  
  <ul>
  <li>C:\Test\Item1</li>
  <li>C:\Test\Item2</li>
  <li>C:\Test\Item3</li>
  </ul>
  
  <p>And the folders Item1, Item2 and Item3 have many subfolders and files. </p>
  
  <p>I would like to create a PS that would allow me to delete all the empty subfolders inside Item1, Item2 and Item3 without deleting Item1, Item2 and Item3 folders. It is possible that any of the Item folders is empty, but I don't want to delete them, just the empty content of each folder.</p>
  
  <p>This is just an example, I have a have around 300 Item folders inside Test.</p>
  
  <p>I usually would use this:</p>
  
  <pre><code>$path="C:\TEST"
  
  do {
     $dir = gci $path -directory -recurse | Where { (gci $_.fullName).count -eq 0 } | select -expandproperty FullName
  
     $dir | Foreach-Object { Remove-Item $_ }
  } while ($dir.count -gt 0)
  </code></pre>
  
  <p>But this deletes the folder root folder (Item1, Item2 or Item3) if they are empty.</p>
  
  <p>Thanks in advance.</p>