使用 Robocopy 删除 Windows 上路径过长文件(夹)

使用 Robocopy 删除 Windows 上路径过长文件(夹)

善用好工具

Tools

2016.06.19

👣 #windows #robocopy

Windows Notice for Source Path Too Long

文件名对目标文件夹可能过长。您可以缩短文件名并重试,或者尝试路径较短的位置。

看到这样的提示,略显尴尬,这已经不是第一次在 Windows 上遇到类似删除文件不成功的问题了,所以干脆写个记录以备后患吧。

用到的工具是 Robocopy,它是微软在 Windows Server 2003 Resource Kit Tools 中提供的复制工具,新版的 Windows 中应该已经集成该工具了,如果没有可以到上述网址下载。

好吧,看看怎么删除这样的文件路径过长的文件(夹)吧。

假设要删除的文件夹是 D:\folder-to-delete,那么可以先在 D 盘下新建一个空文件夹 D:\empty-folder

然后再到 cmd 或 powershell 中输入下面命令:

robocopy /MIR D:\empty-folder D:\folder-to-delete

这样就把文件夹 D:\folder-to-delete “复制”成与 D:\empty-folder 一样的空文件夹了,现在想怎么删就怎么删。

当然,现在有 Windows Subsystem for Linux 了,可以用 rm -rf 来删除了。

林宏

Frank Lin

Hey, there! This is Frank Lin (@flinhong), one of the 1.41 billion . This 'inDev. Journal' site holds the exploration of my quirky thoughts and random adventures through life. Hope you enjoy reading and perusing my posts.

YOU MAY ALSO LIKE

Setup an IKEv2 server with strongSwan

Tutorials

2020.01.09

Setup an IKEv2 server with strongSwan

IKEv2, or Internet Key Exchange v2, is a protocol that allows for direct IPSec tunnelling between networks. It is developed by Microsoft and Cisco (primarily) for mobile users, and introduced as an updated version of IKEv1 in 2005. The IKEv2 MOBIKE (Mobility and Multihoming) protocol allows the client to main secure connection despite network switches, such as when leaving a WiFi area for a mobile data area. IKEv2 works on most platforms, and natively supported on some platforms (OS X 10.11+, iOS 9.1+, and Windows 10) with no additional applications necessary.

Install Jekyll on Windows with Chocolatey

Tutorials

2016.06.25

Install Jekyll on Windows with Chocolatey

In this installation guide we’ll be using Windows 10 & package manager Chocolatey. These instructions should also work for older versions of Windows.

Ads by Google