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

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

善用好工具

Tools

2016.06.19

14 👣 #windows #robocopy

Windows Notice for Source Path Too Long 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.

logout

上阳白发人

白居易「唐代」

上阳人,上阳人,红颜暗老白发新。

绿衣监使守宫门,一闭上阳多少春。

玄宗末岁初选入,入时十六今六十。

同时采择百余人,零落年深残此身。

忆昔吞悲别亲族,扶入车中不教哭。

皆云入内便承恩,脸似芙蓉胸似玉。

未容君王得见面,已被杨妃遥侧目。

妒令潜配上阳宫,一生遂向空房宿。

宿空房,秋夜长,夜长无寐天不明。

耿耿残灯背壁影,萧萧暗雨打窗声。

春日迟,日迟独坐天难暮。

宫莺百啭愁厌闻,梁燕双栖老休妒。

莺归燕去长悄然,春往秋来不记年。

唯向深宫望明月,东西四五百回圆。

今日宫中年最老,大家遥赐尚书号。

小头鞵履窄衣裳,青黛点眉眉细长。

外人不见见应笑,天宝末年时世妆。

上阳人,苦最多。

少亦苦,老亦苦,少苦老苦两如何!

君不见昔时吕向美人赋,

又不见今日上阳白发歌!