59

I need to make backups of some files on a network share. However, I need to copy those files to my local drive before burning the disks because those files might be in use. Some of the files won't copy because the file path is too long. Is there any workaround other than changing the file structure?

1

6 Answers 6

28

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.

0
80
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.

5
  • 7
    This is the solution. If you want to turn OFF support for paths with length greater than 256, pass in the /256 flag. Thanks a lot! I have struggled with this all day.
    – Automatico
    Apr 26, 2015 at 0:40
  • 3
    Great solution - couple of further notes: (1) destination should include the folder name if copying the folder - e.g. if copying C:\Windows to D:\Windows the command would be robocopy /E C:\Windows D:\Windows (i.e. not robocopy /E C:\Windows D:\). (2) Can move files instead of copying them by using the /MOVE option. Jul 31, 2017 at 8:57
  • On Windows, this is a reliable solution for NAS usage. You can start a copy of millions of files, and if the transfer is interrupted half-way through, it will pick up where it left off, not re-copying all files that have already have been transfered. It's really valuable when you have a Wifi connection that drops intermittently, and still want to be able to move large numbers of files with guaranteed completion.
    – user19496
    May 1, 2018 at 10:54
  • 1
    This doesn't work for files that have invalid names on windows. Is there a flag for this that will help?
    – Richard
    Feb 12, 2019 at 17:06
  • 2
    @Richard : The discussion resulting from the question I asked about Robocopy's poison characters might assist you: stackoverflow.com/questions/45666682/…
    – Ed999
    Apr 30, 2019 at 1:54
19

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.

1
  • 2
    This is a really great tip. I also works to get around handling com1, com2 etc filenames. Jan 6, 2015 at 11:58
4

FastCopy is open source C project written by SHIROUZU Hiroaki and is "The Fastest Copy/Delete Software on Windows." It supports UNICODE and over MAX_PATH (260 characters) file path names.

If you have hundreds of paths that are too long to fix, use "Path Tool Long Auto Fixer" Tool

2
  • 2
    FastCopy is really quite excellent. In particular, unlike RoboCopy it does useful things with directory junctions/soft links.
    – rlpowell
    May 16, 2017 at 23:52
  • 1
    Excellent. Alternately, there is a SO answer that lists similar fast-copy programs that are also usually extended-path compliant.
    – ingyhere
    Dec 25, 2017 at 19:00
1

I use a much more easier software solution:

FreeFileSync(Portable) to do the job beautifully. (it DO NOT have long file name restriction)

You might either

1) Using FreeFileSync to copy files at the very beginning, OR

2) in my case, I have copied files with Explorer, it alerts me that some files are not copied because of long file names. Then I use FreeFileSync to sync the remaining (non-copied) files.

The good thing is: the copy speed is quite fast.

-3

Quickest fix I used in this situation was to rename the over-long name folders to something like "1".

Also, as a general practice, I try to explain all users not to put their life story into a file or folder name.

Any decent file manager can handle longer than 260 character file names.

Not the answer you're looking for? Browse other questions tagged or ask your own question.