Finding truly empty folders with Powershell

The easiest approach to find empty folders with Powershell could be:

(gci C:\Scripts -r | ? {$_.PSIsContainer -eq $True}) | ? {$_.GetFiles().Count -eq 0} | select FullName

however this just finds the folders which have no files in them. To find truly empty folders – the one which also have no subfolders – use the following:

(gci C:\Scripts -r | ? {$_.PSIsContainer -eq $True}) | ?{$_.GetFileSystemInfos().Count -eq 0} | select FullName

Source: http://superuser.com/questions/321231/how-to-find-empty-directories-in-windows-using-a-powershell-script

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website