How to recursively remove all empty folders in PowerShell?

前端 未结 13 2708
野趣味
野趣味 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:58

    $files = Get-ChildItem -Path c:\temp -Recurse -Force | where psiscontainer ; [array]::reverse($files)
    

    [Array]::reverse($files) will reverse your items, so you get the lowest files in hierarchy first. I use this to manipulate filenames that have too long filepaths, before I delete them.

提交回复
热议问题