用 robocopy 删除“路径太长”无法删除的文件夹

资源管理器删不掉的超长路径文件夹,用一个空文件夹镜像覆盖即可清空。

Windows文件系统robocopy 文件复制高风险
先新建空文件夹,再运行 `robocopy C:\EmptyDir "C:\Very\Long\Path\Folder" /MIR` 清空长路径内容,最后删除空壳。

01命令

命令
$ mkdir C:\EmptyDir && robocopy C:\EmptyDir "C:\Very\Long\Nested\Path\Folder" /MIR && rmdir /s /q C:\EmptyDir

02作用说明

当路径超过传统的 260 字符限制时,资源管理器和 Remove-Item 都会报错,而 robocopy 原生支持长路径。用 /MIR 把一个空文件夹镜像到目标位置,会删除目标下的所有文件和子文件夹,之后用 rmdir 删除空壳即可。这个技巧同样适用于个别删不掉的顽固文件。

03风险

风险高风险
使用条件Built into Windows 10/11; no long-path registry change needed.
!注意: /MIR 会删除目标端所有源端没有的内容——路径写错就会误删别的文件夹,运行前务必核对。

04撤销

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

05来源

  • robocopy
    Microsoft Learn · vendor-doc · 2026-09-17
    依据: Documents the /MIR switch (mirror a directory tree, deleting destination items not in the source) and handles long paths.
  • Robocopy — Robust file copy
    SS64 · technical · 2026-09-17
    依据: Describes /MIR as equivalent to /PURGE plus /E — mirroring an empty folder deletes everything under the target path.

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

06相关方案