How to copy files that have too long of a filepath in Windows?
robocopy /E source destination
Robust File and Folder Copy.
Windows 7 and above, (including Windows 10):
Robocopy XP027 is a standard command on Windows 7 and above.
Windows versions > 7 may have other Robocopy versions,
as Robocopy is still maintained.
Please read the link above for more details regarding,
limitations in specific versions of Robocopy.
NT 4/ Windows 2000:
The Windows Server 2003 Resource Kit Tools include Robocopy XP010,
which can be run on NT 4/ Windows 2000.
Windows 95, or NT 3.5:
Robocopy does not run on Windows 95, or NT 3.5. (Robocopy is a Unicode application).
Windows 95, or NT 3.5 workaround:
The Microsoft Robocopy GUI will install Robocopy XP026 to C:\Windows\system32,
this version can run on older OS's,
and includes some features from XP027 (/BYTES) but has competely broken errorlevel handling.
Robocopy 'Jobs' and the 'Monitor source' option provide an alternative to setting up a Scheduled Task to run a batchfile with a Robocopy command.
Maximum path length is 260 in Windows Vista/7. I can recommend three solutions:
- (if the path is too long) First copy the folder to upper levels in windows explorer and then move it to your local computer
- (if file names are too long) First try to zip/rar/7z them with an archive application and then copy the archive file to your local computer and then extract the contents.
- Use third party apps.
All of these suggestions assume you have some sort of write access on the network shared folder/computer. If you can't do any of these then you might need help from your administrator.
You can access path lengths up to ~32,767¹ characters by prefixing them with \\?\
.
\\?\C:\Some\Really\Long\Path
This works from the command prompt and any other programs which use the Win32 Unicode Api methods, including .Net apps.
(Documentation)
It does require a file system that supports long paths (eg NTFS) but if you have a long path problem, that's a given.
Note that certain applications and a lot of native tools (like Explorer) will have problems with these paths so use this to get yourself out of a hole, not into one.
You can also use a variant \\?\UNC\
to access long paths across network shares...
\\?\UNC\server_name\share_name\...
¹ For those that are interested, it is 32,767 not 32,768 as it's a null-terminated string, but the \\?\
may be expanded, consuming some characters, so don't rely on the count being precise.