windows复制文件夹_为什么Windows报告此文件夹太长而无法复制?

windows复制文件夹

windows复制文件夹

If you work with Windows long enough, especially with folders and files that have long names, you’ll run into a bizarre error: Windows will report that the folder path or file name is too long to move to a new destination or even delete. What’s the deal?

如果您使用Windows的时间足够长,尤其是使用具有长名称的文件夹和文件,则会遇到一个奇怪的错误:Windows将报告文件夹路径或文件名太长而无法移动到新目的地甚至删除。 这是怎么回事?

Hey How-To Geek!

嘿,怪胎!

So the other day, I was reorganizing some files on my computer, creating folders, that kind of stuff. Then, when I was moving some files into a folder, I get a message, stating that the resulting folder path would be too long. I was confused. I know that every single OS since DOS supports Long Filenames, yet Windows claims that the path is too long? Why does this happen?

因此,前几天,我在计算机上重新整理了一些文件,创建了文件夹之类的东西。 然后,当我将某些文件移动到文件夹中时,我收到一条消息,指出生成的文件夹路径将太长。 我很困惑。 我知道自DOS以来每个操作系统都支持长文件名,但是Windows声称路径太长了? 为什么会这样?

Sincerly,

真诚的

Mr. Disorganized

杂乱无章的先生

The problem you’re running into is an unfortunate intersection of two systems that, in cases like this, yields an error. To understand exactly where the error comes from, we need to dig into the the history of Long Filenames (LFN) and how Windows interacts with them before we delve into solutions.

您遇到的问题是两个系统的不幸交集,在这种情况下会产生错误。 为了确切地了解错误的出处,我们需要深入研究长文件名(LFN)的历史以及Windows如何与它们交互,然后再研究解决方案。

Long Filenames were introduced, through the underlying MS-DOS architecture, in Windows 95. The new LFN system allowed for file and directory names of up to 255 characters. This was a welcome expansion of the previous file name system, usually called 8.3 filenaming because the name was limited to eight characters and a three digit extension, but also known as Short Filename (SFN). As you can imagine, back then there were still a lot of DOS-based apps around and there were more than a few headaches trying to get the newer LFNs and the legacy SFNs to play nice with each other. If you’ve ever come across an older diskette or CD-ROM with oddly truncated files on it (like abcdef~1.txt) that filename was cut down by some SFN-using legacy application from some longer and unsupported LFN (like abcdefghijk.txt).

Windows 95通过底层的MS-DOS体系结构引入了长文件名。新的LFN系统允许文件和目录名最多255个字符。 这是对以前的文件名系统的一个受欢迎的扩展,通常称为8.3文件名,因为该名称限制为八个字符和三个数字的扩展名,但也称为短文件名(SFN)。 可以想象,那时仍然有很多基于DOS的应用程序,并且尝试让新的LFN和旧式SFN相互配合时,头痛不已。 如果您曾经遇到过旧的软盘或CD-ROM,但文件上的文件被截断了(例如abcdef〜1.txt),则该文件名已被某些使用SFN的旧版应用程序从一些较长且不受支持的LFN(例如abcdefghijk)中删除。文本)。

We’re a long way from the mid-1990s, however, and the whole Long Filename thing is (for the most part) firmly ironed out. If you’re running a version of Windows from the last 10 years, you’ve likely never even come across a filename length conflict like we we used to run into back in the DOS/Windows 95 days. That said, we still run into hiccups, as you discovered with your disk cleanup project. But why? If Windows’ Long Filename system supports folders and file names of up to 255 characters per component, what wall are you running into? We can’t blame NTFS (the filesystem that the vast majority of modern Windows machines use) as NTFS will support a chaining of folders and file names up to a total path length of 32,767 characters. That far exceeds the typical directory structure most users would ever need.

但是,与1990年代中期相比,我们还有很长的路要走,而且整个Long Filename事情(大部分情况下)都已得到明确解决。 如果您运行的是过去十年的Windows版本,您可能甚至从未遇到过文件名长度冲突,就像我们过去在DOS / Windows 95天内遇到的那样。 也就是说,正如您在磁盘清理项目中发现的那样,我们仍然遇到麻烦。 但为什么? 如果Windows的Long Filename系统支持每个组件最多255个字符的文件夹和文件名,那么您将遇到什么障碍? 我们不能责怪NTFS(大多数现代Windows机器使用的文件系统),因为NTFS将支持文件夹和文件名的链接,最长路径长度为32,767个字符。 这远远超出了大多数用户所需的典型目录结构。

Where it all falls apart is an artificial restriction Windows stacks on top of the LFN/NTFS system: the MAX_PATH variable. The MAX_PATH variable specifies that a complete directory structure in Windows can’t exceed 260 total characters, including the drive letter, colon, backslash, and null backlash at the end. Thus you only have a potential real MAX_PATH of 256 characters, e.g. C:\your-256-character-path\.

在LFN / NTFS系统顶部,人为限制Windows堆栈的地方是:MAX_PATH变量。 MAX_PATH变量指定Windows中完整的目录结构不能超过260个字符,包括驱动器号,冒号,反斜杠和结尾的空反斜杠。 因此,您可能只有256个字符的实际MAX_PATH,例如C:\ your-256-character-path \

So what happened when you were cleaning up your computer is that you had a directory with an already long path (either because the folder names were long, the file names were long, or both), and when you attempted to move one or more of those directories into another directory with a long path, the total length of the path name exceeded the 260 character limit imposed by the MAX_PATH variable.

因此,清理计算机时发生的事情是,您的目录中的路径已经很长(或者因为文件夹名太长,文件名太长或两者兼而有之),并且当您尝试移动一个或多个将这些目录放入具有长路径的另一个目录中,路径名的总长度超过了MAX_PATH变量施加的260个字符的限制。

Now, you may be thinking “Ah-hah! We’ll just change the MAX_PATH variable and solve the problem!” Alas, it’s not that simple. Not only is the MAX_PATH variable essentially hard coded into Windows, but even if you went through the enormous hassle of changing it, you’d end up breaking so much it wouldn’t be worth it. Too many applications expect the path variable to be what Windows has long specified it to be. We can’t just go around changing it without creating an enormous mess.

现在,您可能在想:“啊哈哈! 我们只需更改MAX_PATH变量即可解决问题!” las,这不是那么简单。 不仅将MAX_PATH变量从本质上硬编码到Windows中,而且即使经历了巨大的更改麻烦,您最终也要付出太多代价,这是不值得的。 太多的应用程序期望path变量是Windows早已指定的变量。 我们不能仅仅改变它而不会造成巨大的混乱。

Where does that leave you? Well, the simplest solution is to just edit the path data. For example, if you have a ton of saved articles where the application/extension you used to save them from the web created a directory that was the full title of the article + the article lead, and then the file name itself is the full title of the article + the article lead, it would be really simple to hit or exceed the MAX_PATH with a single save. Editing those enormous folder and article titles down to a more reasonable size is an easy way to fix the problem.

那会留在哪里? 好吧,最简单的解决方案是只编辑路径数据。 例如,如果您有大量已保存的文章,而您用来从网上保存它们的应用程序/扩展名创建了一个目录,该目录是文章的完整标题+文章线索,然后文件名本身就是完整标题的文章+文章的标题,只需保存一次即可达到或超过MAX_PATH,这非常简单。 将这些巨大的文件夹和文章标题编辑为更合理的大小是解决问题的简便方法。

If you have a huge number of files with a long path and you don’t want to edit them all (or if you want to delete a ton of old directories that are too long for Windows to deal with when restricted by the MAX_PATH variable), there is a command-line work around. Even though Windows is restricted by the MAX_PATH variable, Windows engineers realized there would be situations wherein users would need to deal with longer path names. As such, the Windows API has a function for dealing with extremely long paths.

如果您有大量文件且路径较长,并且不想全部编辑它们(或者如果要删除一堆旧目录,这些目录在受MAX_PATH变量限制时对于Windows来说太长了) ,这里有一个命令行解决方法。 即使Windows受MAX_PATH变量限制,Windows工程师也意识到,在某些情况下,用户需要处理更长的路径名。 因此,Windows API具有处理极长路径的功能。

In order to take advantage of that API and use command line tools on your unwieldy folders/file names, you simply need to append the directory name with a few extra characters. For example, if you had a huge directory structure that you wanted to delete (but received an error due to the path length when you attempted it), you could change the command from:

为了利用该API并在笨拙的文件夹/文件名上使用命令行工具,您只需要在目录名后附加一些额外的字符。 例如,如果您有一个想要删除的巨大目录结构(但是由于尝试路径长度而收到错误),则可以将命令更改为:

rmdir c:\documents\some-really-super-long-folder-name-scheme\

rmdir c:\documents\some-really-super-long-folder-name-scheme\

to:

至:

rmdir \\?\c:\documents\some-really-super-long-folder-name-scheme\

rmdir \\?\c:\documents\some-really-super-long-folder-name-scheme\

The key is the addition of the \\?\ portion before the start of the file path; this instructs Windows to disregard the limitations imposed by the MAX_PATH variable and to interact with the path you just supplied as supplied/understood directly by the underlying files system (which can clearly support a longer path). As always, exercise caution at the command prompt to avoid accidentally deleting files or directories you intended to leave intact.

关键是在文件路径开始之前添加\\?\部分; 这指示Windows忽略MAX_PATH变量施加的限制,并与基础文件系统直接提供或理解的刚提供的路径进行交互(显然可以支持更长的路径)。 与往常一样,请在命令提示符下格外小心,以免意外删除要保留原样的文件或目录。

If our overview of this issue has you curious, definitely dig into this article from the Microsoft Developer Network library, Naming Files, Paths, and Namespaces, for more information about what’s going on under the hood.

如果您对我们的问题概述感到好奇,请一定要从Microsoft开发人员网络库,命名文件,路径和命名空间中深入了解本文,以获取有关幕后情况的更多信息。



Have a pressing tech question? Shoot us an email at ask@howtogeek.com and we’ll do our best to answer it.

有紧迫的技术问题吗? 向我们发送电子邮件至ask@howtogeek.com,我们将尽力答复。

翻译自: https://www.howtogeek.com/179173/ask-htg-why-is-windows-reporting-this-folder-is-too-long-to-copy/

windows复制文件夹

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值