CodShot
PowerShell Public

Remove Empty Folders

Remove empty folders under the current directory.

#powershell #folders #cleanup #windows
PowerShell
Get-ChildItem -Directory -Recurse |
    Sort-Object FullName -Descending |
    Where-Object { -not (Get-ChildItem -Path $_.FullName -Force) } |
    Remove-Item -Force

Notes

This removes only empty folders. Test it in a safe folder first.

Snippet actions

CodShot user
CodShot user
Updated: 2026-06-03 15:31
Public snippets
0
Forks
CodShot AI Help
Ask about CodShot features, plans, workspace, AI limits, referrals, and public help topics.
Hi! I can help you understand how CodShot works. What would you like to know?
For account-specific or sensitive issues, please open a support ticket. Open support