Folder is Too Long to Copy Issue

May 24th, 2014 by Rossy Guide

What is that issue?

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.

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 history of Long Filenames (LFN) and how Windows interacts with them before we delve into solutions.

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).

How it can be fixed?

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.

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.

It’s that ^^^ or u have too many folders in just one folder and remember all the folder names behind each other makes your error. Windows support only so many digits in the name and root of the folder. Go a few folders inside and shorten the names of the long name of the folder and extremely long file names.

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:

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

to:

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.

Comments are closed.