How to recursively remove all empty folders in PowerShell?

前端 未结 13 2709
野趣味
野趣味 2020-12-08 02:23

I need to recursively remove all empty folders for a specific folder in PowerShell (checking folder and sub-folder at any level).

At the moment I am using this scrip

13条回答
  •  庸人自扰
    2020-12-08 02:54

    Assuming you're inside the parent folder of interest

    gci . -Recurse -Directory | % { if(!(gci -Path $_.FullName)) {ri -Force -Recurse $_.FullName} }

    For your case with $tdc it'll be

    gci $tdc -Recurse -Directory | % { if(!(gci -Path $_.FullName)) {ri -Force -Recurse $_.FullName} }

提交回复
热议问题