Hardly a month goes by when I don't run into this little gem while copying files:
Here's an overly simplified explanation of what causes this error: When copying a file or folder, Windows requires the resulting destination path of the file/folder to be less that 260 characters. The error occurs because the destination path of one or more files being copied would exceed this 260 character limit. As we'll see, however, if we could somehow get the files to be copied, Windows is perfectly at peace with files whose qualified paths are greater than 260 characters. The problem arises in actually getting the files copied.
I'm going to show you a simple way to get around this error that's easy to use and works in the vast majority of cases where this error crops up. This technique is not a "fix" in that the underlying cause of the problem will still exist but at least you'll be able to copy/move the file(s) to the destination directory.
Let's say we have some files or folders that we want to copy into the directory, c:\Very\Very\Long\Destination\Directory
. I'll refer to this directory simply as, the destination directory, from now on. I'll refer to the files/folders to be copied as the source files from now on.
To successfully copy the source files, we'll first set up a temporary "virtual drive" that will serve as an alias for the destination directory (don't worry, it's easy). We'll then copy the source files to this virtual drive. Once we're finshed, we'll remove the virtual drive with our source files safely residing in the destination directory. To start out, open a command prompt. If you don't know how to do this, hold down the Windows key and simultaneously press the letter R on the keyboard. A small window will pop up in the lower left corner of the screen. Type cmd
into this window and press the OK button:
After pressing the OK button, a command window will appear. (This window used to be known as a "DOS Window", in King Arthur's time.) At the command prompt, type the command shown below, substituting your own destination directory for "c:\Very\Very\Long\Destination\Directory"
. If you already have a W:
drive on your computer, be sure to use a drive letter that's not in use. Do not type a trailing backslash character after the destination directory. Use the format shown below.
subst W: "c:\Very\Very\Long\Destination\Directory"
At this point you should have a new W:
drive on your computer. This new drive is simply an alias for the destination directory. Anything you copy to or from the new drive will actually be copied to or from the destination directory. Now, go back to Windows Explorer and drag the source files to the newly created W:
drive. This will have the effect of copying the source files to the destination directory. Once everything's been copied, you'll want to remove the alias drive. Return to the command window and enter this command to disassociate the W:
drive letter from the destination directory:
subst /d W:
Feel free to close the command window. You should now see the source files are present in the destination directory.
It's interesting (and a bit odd) that Windows did not allow us to copy the source files to the destination directory initially due to the fact that one or more resulting paths would have been over 260 characters; yet, after copying to the drive alias, Windows is perfectly happy to allow the newly copied files to exist in the destination directory, even though the resulting path lengths of these files may be well over the 260 character "limit". If you are very technically inclined and you have an interest, you can read a relevant blog post about long paths in .NET.