We live in times of Big Data. Too much data in too short a time. You may have empty folders in your environment and if you want to search for them and delete them then you are at the right place. We will do just that.
Run this little script below to remove all empty folders.
At the top you need to specify the path to the root folder. In my case this is C:\Data. You will be asked to confirm the deletion.
# Get a list of all folders
$rootfolder = "C:\Data"
$folders = Get-ChildItem -Path $rootfolder -Directory -Recurse
# Filter out the empty folders
$emptyFolders = $folders | Where-Object {$_.GetFileSystemInfos().Count -eq 0}
# Delete the empty folders
$emptyFolders | Remove-Item -Force -Verbose
And here is the code in Action.
We have now cleaned up a bit. That’s good.
Categories: PowerShell, Windows 10, Windows 11, Windows Server
3 replies »