How to copy files that have too long of a filepath in Windows?

53

26

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?

Brian Sturm

Posted 2010-11-30T13:44:57.093

Reputation: 1 048

1

See also Window 256 characters path name limitation.

– Gilles 'SO- stop being evil' – 2010-12-01T00:59:18.713

Answers

27

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.

Gani Simsek

Posted 2010-11-30T13:44:57.093

Reputation: 2 510

@BrianSturm, Well, assuming they are 3rd party apps – Pacerier – 2015-05-16T00:24:23.213

Although I really hate this about Windows...the zip solution really saved my day. Thanks! – Bas Slagter – 2015-09-18T08:43:29.363

8zipping the files worked! – Brian Sturm – 2010-11-30T21:19:57.070

67

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.

user19496

Posted 2010-11-30T13:44:57.093

Reputation: 1 205

6This 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 – 2015-04-26T00:40:35.160

1amazing! Solution i never know until now this bult-in solution. – SIslam – 2015-10-12T08:01:54.950

2Great 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. – Steve Chambers – 2017-07-31T08:57:15.227

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 – 2018-05-01T10:54:16.863

1This doesn't work for files that have invalid names on windows. Is there a flag for this that will help? – Richard – 2019-02-12T17:06:46.313

1

@Richard : The discussion resulting from the question I asked about Robocopy's poison characters might assist you: https://stackoverflow.com/questions/45666682/powershell-in-a-batch-file-how-do-you-escape-metacharacters

– Ed999 – 2019-04-30T01:54:56.220

18

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.

Basic

Posted 2010-11-30T13:44:57.093

Reputation: 945

2This is a really great tip. I also works to get around handling com1, com2 etc filenames. – Andreas Reiff – 2015-01-06T11:58:32.137

3

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

Markus

Posted 2010-11-30T13:44:57.093

Reputation: 169

2FastCopy is really quite excellent. In particular, unlike RoboCopy it does useful things with directory junctions/soft links. – rlpowell – 2017-05-16T23:52:19.407

1

Excellent. Alternately, there is a SO answer that lists similar fast-copy programs that are also usually extended-path compliant.

– ingyhere – 2017-12-25T19:00:54.693

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

Overmind

Posted 2010-11-30T13:44:57.093

Reputation: 8 562