windows 如何在windows中删除长路径。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/551072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:03:58  来源:igfitidea点击:

How to delete a long path in windows.

windowseclipsepath

提问by Baltimark

When importing a project into eclipse, it somehow started creating recursive versions of the directory.

将项目导入 Eclipse 时,它​​以某种方式开始创建目录的递归版本。

Now, when I try to delete anything, I get the message " the file name you specify is too long."

现在,当我尝试删除任何内容时,我收到消息“您指定的文件名太长。”

I can't delete it from the command shell. I can't delete it from explorer. I can't do ANYTHING with it. I have no idea how many copies of it Eclipse created. Eclipse was running for like a minute before I realized something was wrong and I cancelled the operation.

我无法从命令外壳中删除它。我无法从资源管理器中删除它。我不能用它做任何事情。我不知道 Eclipse 创建了多少个副本。Eclipse 运行了大约一分钟,然后我才意识到出现问题并取消了操作。

I can get the properties of the top level folder, and it says it contains 497 folders.

我可以获取顶级文件夹的属性,它说它包含 497 个文件夹。

Question 1: how can I delete all this stuff in Windows?

问题 1:如何在 Windows 中删除所有这些东西?

Question 2: What the hell was eclipse thinking?

问题2:日食到底在想什么?

采纳答案by Ian Hopkinson

I had a problem similar to this with Eclipse: trying to import a project using Subclipse, it generated a deeply nested set of directories which I couldn't delete.

我在 Eclipse 中遇到了与此类似的问题:尝试使用 Subclipse 导入一个项目,它生成了一组我无法删除的深度嵌套目录。

I did a couple of things, firstly I edited the directory names down to the shortest length possible (actually I think this was pointless). Secondly, I traversed the directory tree as deeply as possible and then cut and pasted the branch out (which makes it possible to delete the original branch), and then repeated the process.

我做了几件事,首先我将目录名称编辑到尽可能短的长度(实际上我认为这是毫无意义的)。其次,我尽可能深入地遍历目录树,然后将分支剪切粘贴出来(这样可以删除原始分支),然后重复该过程。

@Charlie and @Tomalek's solutions look like they might be more elegant. I don't plan on repeating the experience to find out though.

@Charlie 和 @Tomalek 的解决方案看起来可能更优雅。我不打算重复经验来找出答案。

回答by gonsalu

robocopy empty_dir base_nested_dir /purge

Example: If you have a folder path that's too long such as:

示例:如果您的文件夹路径太长,例如:

D:\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles

D:\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles\BackupFolder\Copy\MyFiles

follow these instructions to delete it.

按照这些说明删除它。

  1. Create an empty folder, such as C:\Users\Name\Desktop\temp.
  2. Open a Command Prompt window.
  3. Type robocopy C:\Users\Name\Desktop\temp D:\BackupFolder /purge
  1. 创建一个空文件夹,例如C:\Users\Name\Desktop\temp.
  2. 打开命令提示符窗口。
  3. 类型 robocopy C:\Users\Name\Desktop\temp D:\BackupFolder /purge

Note: If there are spaces in either path in Step 3, the path must be inclosed by quotation marks.

注意:如果步骤 3 中的任一路径中有空格,则路径必须用引号引起来。

回答by Swanidhi

7Zip is the ultimate solution if you are not comfortable with command-line.

如果您对命令行不满意,7Zip 是终极解决方案。

  1. Open 7Zip File Manager
  2. Navigate to your file
  3. Shift-Delete your file
  1. 打开 7Zip 文件管理器
  2. 导航到您的文件
  3. Shift-删除您的文件

Cheers!

干杯!

回答by Tomalak

As to Q1)

至于 Q1)

Use subst to short-cirquit the paths:

使用 subst 来缩短路径:

subst Q: C:\very\long\path\created\by\eclipse
Q:
del *.*

As to Q2)

至于 Q2)

Long paths are less of a problem in other OSes, and there are Windows API functions that candeal with paths longer than 255 characters, so they just did it, I guess.

长路径在其他操作系统中不是问题,并且有 Windows API 函数可以处理超过 255 个字符的路径,所以我猜他们只是这样做了。

回答by Charlie

If you need to deal with paths longer than MAX_PATH, you'll have to use the Unicode versions of the Windows file APIs (e.g. DeleteFileW) and use the \\?\ prefix. You can write a short program using these APIs to enumerate these directories and delete them.

如果您需要处理长于 的路径MAX_PATH,则必须使用 Unicode 版本的 Windows 文件 API(例如DeleteFileW)并使用 \\?\ 前缀。您可以使用这些 API 编写一个简短的程序来枚举这些目录并删除它们。

回答by Haitham Sweilem

The fix is simple and free! No need to rename the folders at all.

修复简单且免费!根本不需要重命名文件夹。

  1. Download Cygwinfor free.

  2. use the command rm -f -r <folder-name>and wait a few moments.

  1. 免费下载Cygwin

  2. 使用命令rm -f -r <folder-name>并稍等片刻。

I had a folder of size 1.5 GB with numerous inner folders and it worked!

我有一个大小为 1.5 GB 的文件夹,里面有许多内部文件夹,它工作正常!

回答by Izzy Weird

A method mentioned in this Windows Sysinternals forum post by maxaha1worked.

maxaha1此 Windows Sysinternals 论坛帖子中提到的方法有效。

I suggest that you work top down. As long as you stay within the same volume (share), you can usually drag the upper level directories to new parents, without regard for the contents of the directory being dragged (ie. and the length / recursion issues it might have). So you take a directory maybe 4 or 5 levels down your problem path, and drag it to the root. Then delete the original path that now only contains a few levels. Ideally, work to keep the longest path to less than 250 chars (includes filenames). I'm doing a system migration at the moment, and we have some users with 340+ char paths which dont copy without this method. I've tried subst's, recursive net use's, recursive scripts, etc.. Unfortunately, users seem to be able to create things that befuddle the best coders, admins etc..

我建议你自上而下工作。只要您保持在同一个卷(共享)内,您通常可以将上层目录拖动到新的父目录,而无需考虑被拖动目录的内容(即它可能具有的长度/递归问题)。因此,您可能会在问题路径下的 4 或 5 层处取一个目录,并将其拖到根目录。然后删除现在只包含几个级别的原始路径。理想情况下,尽量保持最长路径少于 250 个字符(包括文件名)。我目前正在进行系统迁移,我们有一些用户拥有 340 多个字符路径,如果没有这种方法就无法复制。我尝试过 subst、递归网络使用、递归脚本等。不幸的是,用户似乎能够创造出让最好的编码人员、管理员等感到困惑的东西。

Create new folders and just drag-and-drop, several folders down from the top each time (and delete them) until you get it all cleaned up.

创建新文件夹,然后每次从顶部向下拖放几个文件夹(并删除它们),直到将它们全部清理干净。

回答by F.M.

The previous three responses are obviously spam (for a payware demo). If you want a free one-click solution, see here:

前三个回复显然是垃圾邮件(用于付费软件演示)。如果您想要免费的一键式解决方案,请参阅此处:

http://www.osmstudios.com/Display.asp?Page=pathtoolong

http://www.osmstudios.com/Display.asp?Page=pathtoolong

Which probably employs the 3-line Java from further up this thread.

这可能使用了该线程更上层的 3 行 Java。

-fm

-调频

回答by rachel

i'd faced the same problem using eclipse..! a zillion nested folders got created and it took up more than 500MB space!!!!

我在使用 eclipse 时遇到了同样的问题..!创建了无数个嵌套文件夹,占用了超过 500MB 的空间!!!!

i tried a ton of things in windows and nothing worked..

我在 Windows 中尝试了很多东西,但没有任何效果。

finally i just rebooted using ubuntu and deleted that horrible folder.. just like that.. ubuntu doesn't seem to have any such access restrictions based on filepath length as windows does.. makes life a lot easier.. :)

最后,我只是使用 ubuntu 重新启动并删除了那个可怕的文件夹.. 就像那样.. ubuntu 似乎没有任何基于文件路径长度的访问限制,就像 Windows 那样.. 让生活更轻松.. :)

回答by John

Programmatically you can delete using DeleteFileWand RemoveDirectoryW, and prepending L"\\?\"to the file names. Note that you have to use the W version not the A version of the APIs.

以编程方式,您可以使用DeleteFileWRemoveDirectoryW, 并L"\\?\"在文件名前删除。请注意,您必须使用 W 版本而不是 A 版本的 API。