Xcopy: Insufficient Memory

Here is an interesting issue I ran into today. I have a script which creates a local copy of one of the important folders on the server using the xcopy command. To make the long story short, after several “accidents” with people messing up or deleting files on the server, we figured that letting people to make local mirrors on their own desktops might be slightly better than restoring stuff back from the tape 4 times a day.

It was something along the lines of:

rmdir /S /Q "%HOMEPATH%\My Documents\Important"
xcopy /E /R /Y /I G:\Important "%HOMEPATH%\My Documents\Important"

The script worked fine for almost a year now. Today however it decided to fail. After copying 1 or 2 folders it would simply stop. After closer inspection of the output I noticed that the last line was:

Insufficient Memory

I immediately checked the memory. The machine had 512 MB of RAM, and over 20 GB of free disk space. The folder I was attempting to copy had only 128 MB. This could not be correct.

Quick google confirmed this – the “insufficient memory” message is very misleading. It appears that this message shows up when the fully qualified (ie. with path) name of the copied file is longer than 254 characters which seems to be Windows maximum path length. Yes – even in WinXP SP2 and Win 2k3. Thank you Microsoft!

So I’m guessing the message doesn’t really refer to the actual free memory, but to the amount of space left in the file name buffer… Or at least I hope that’s what it means. Either that or MS just decided to make “insufficient memory” one of those lovely have a “catch all exceptions and errors here” clauses.

There are essentially 3 workarounds to this:

  1. fix your paths – you can try using virtual drives, junctions and all that jazz to make the source and destination paths shorter. Still, this does not mean that a trigger happy user won’t build a crazy long directory tree in your important folder in the future
  2. Use xxcopy – a 3rd party xcopy clone. It was suggested by David at blogdom.org. This actually worked for me but I’m not entirely happy with this solution. The good part is that xxcopy implements almost all the regular xcopy switches. The bad part is that to use it for commercial purposes you are supposed to pay up $20 or more.
  3. Use robocopy – which seems to be the optimal solution. Robocopy is a part of Windows Server 2003 Resource Kit. The kit will only install on Windows XP and 2003 but robocopy will work on any NT compatible machine. Just install the kit on some machine and copy robocopy.exe from it to all the workstations that need it

The added benefit of using robocopy is that it actually simplified my script:

robocopy \\server\share\Important "%HOMEPATH%\My Documents\Important"

Robocopy can snag the copies directly from the network share, so I do not have to worry about having correct drive letters assigned to the correct shares. This was never really a problem for me since I use login scripts to mount shares on our network, but it is a good thing nevertheless.

In addition robocopy does true mirroring – it will purge all the files in the destination folder which do not appear in the source, saving me the headache of deleting the whole folder prior to copying.

In conclusion – xxcopy works, but robocopy works better. Get it and use it.

[tags]xcopy, xcopy insufficient memory, insufficient memory, xxcopy, robocopy, windows[/tags]

This entry was posted in sysadmin notes and tagged . Bookmark the permalink.

10 Responses to Xcopy: Insufficient Memory

  1. mrbios UNITED STATES Opera Windows says:

    I have the same problem with xcopy on xp sp2+ copying over a network mapped drive. It misses files. I suspect long path names or certain system files?

    Reply  |  Quote
  2. Luke Maciak UNITED STATES Mozilla Firefox Windows Terminalist says:

    Yup – long file paths are usually the cause here. I recommend using Robocopy instead. :)

    Reply  |  Quote
  3. mrbios UNITED STATES Opera Windows says:


    The source drive D: was FAT32 the Target is an xp box share drive formatted with NTFS mapped to Z:\ permissons Everyone Full Control. Both xp pc’s are running xp pro sp2.

    The files that failed to copy were in a stored xp user profile folder (no in use and not in \documents and setings\ so there were no file lock issues. I ziped the user profile folder which was about 10 megabytes and the problem went away.

    I then moved the two user profiles into a dir called d:\delme and created a bunch of really long folder names like “zzzzzzzzzzzzzzzzzzz33” and everything copied find, total files matched and so did size to the byte.

    –> Microsoft does not acknowledge the problem on their web site.

    I copied D:\DRIVERS (FAT32) to E:\DRIVERS (NTFS), both D: and E: are normal local SATA drives / partitions then I performed the copy again and it worked. The total number of files was: 3,438 and ~ 652 megabytes. The copy took an unusually long time 3 or 4 minutes when it should have taken less than 20 seconds. Usually, the copy speed is 30 to 40 MB/sec.

    The problem seems to be related to the network redirector and or aka mapped drive’s inability to properly handle some file/folder name lengths or types going from FAT32 to NTFS.

    Reply  |  Quote
  4. Thank you: I ran into this problem and am testing out the xxcopy solution now but have saved both for future use.

    Reply  |  Quote
  5. mrbios UNITED STATES Opera Windows says:

    Your welcome!

    Reply  |  Quote
  6. bitkahuna UNITED STATES Mozilla Firefox Windows says:

    Thanks very much for posting this. xcopy not copying certain (or in my case THOUSANDS of) files was a real problem. and i’m not using network shares, this is just on a server to an external drive.

    Reply  |  Quote
  7. Anil INDIA Mozilla Firefox Windows says:

    It has the same problem on Win 7 – 64bit! Yikes!

    Reply  |  Quote
  8. Hello there… I had the same problem… I´ve executed the following script:

    xcopy u:\*.* e:\documentos\ /O /C /Y /E /D

    then I´ve tried changing the last parameter

    xcopy u:\*.* e:\documentos\ /O /C /Y /E /J

    In both cases, after one hour I got the same error:


    Do you have an explanation and a solution for this? Thanks in advance

    Reply  |  Quote
  9. FGranados INDIA Google Chrome Windows says:

    @ mrbios:You can also use Long Path Tool to sort out this problem.

    Reply  |  Quote
  10. George UNITED STATES Google Chrome Windows says:

    Thanks for this post, you pointed me the cause of the error. Not memory. Length of path! D’oh!

    Reply  |  Quote

Leave a Reply

Your email address will not be published. Required fields are marked *