用 PowerShell 找出所有空文件夹

用 Get-ChildItem -Recurse -Directory 加计数判断,列出文件夹里所有空目录(含隐藏文件),可再配合删除。

Windows目录清理文件PowerShell低风险
运行 Get-ChildItem -Recurse -Directory 管道,用 Where-Object { (Get-ChildItem $_.FullName -Force | Measure-Object).Count -eq 0 } 筛出空文件夹。

01命令

命令
$ Get-ChildItem 'C:\Data' -Recurse -Directory |
  Where-Object { (Get-ChildItem $_.FullName -Force | Measure-Object).Count -eq 0 } |
  Select-Object -ExpandProperty FullName

02作用说明

只有连隐藏文件都没有的文件夹才算真正的空文件夹,所以内层检查要加 -Force。建议先看列表再决定,真要删除就在命令后加 | Remove-Item;由于删除父文件夹后其空的子文件夹也会跟着消失,重复运行几次可以清得更干净。整理完音乐、照片或卸载软件后,这是很常用的一步收尾。

03风险

风险低风险
!注意: 有些软件会故意保留空文件夹当占位符(配置数据、同步目录),删掉可能报错——执行 Remove-Item 前务必先检查列表。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • Get-ChildItem
    Microsoft Learn · vendor-doc · 2026-09-17
    依据: Get-ChildItem -Directory lists folders; testing whether a folder contains any items (with -Force) identifies empty ones.
  • Get-ChildItem - SS64
    SS64 · technical · 2026-09-17
    依据: Documents -Force to include hidden items and -Directory to restrict results to folders.

最后验证: 2026-09-18 · 分类: 文件与文件夹

06相关方案