Sunday, October 5, 2025
HomePowershellSeek for Empty Folders (and delete them) – SID-500.COM

Seek for Empty Folders (and delete them) – SID-500.COM


PowerShell

We stay in occasions of Huge Information. An excessive amount of knowledge in too quick a time. You will have empty folders in your surroundings and if you wish to seek for them and delete them then you might be on the proper place. We are going to do exactly that.

Run this little script beneath to take away all empty folders.

On the prime you want to specify the trail to the foundation folder. In my case that is C:Information. You’ll be requested to verify the deletion.

# Get a listing of all folders
$rootfolder = "C:Information"
$folders = Get-ChildItem -Path $rootfolder -Listing -Recurse

# Filter out the empty folders
$emptyFolders = $folders | The place-Object {$_.GetFileSystemInfos().Depend -eq 0}

# Delete the empty folders
$emptyFolders | Take away-Merchandise -Power -Verbose

And right here is the code in Motion.

We’ve got now cleaned up a bit. That’s good.

Revealed by Patrick Gruenauer

Microsoft MVP on PowerShell [2018-2023], IT-Coach, IT-Advisor, MCSE: Cloud Platform and Infrastructure, Cisco Licensed Academy Teacher.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments