I created a batch file which copies a directory with xcopy for backup reasons. Then I use pkzip in order to zip the backup folder (and email it through a batch file which is working), but I am getting an error message for insufficient memory. I tried to increase the buffer size in command line properties but it didn't work. I also tried to increase the number of buffers but it didn't work either. Any thoughts/solutions?
The reason I am doing this backup routine is that I want these tasks to be automatically done through Windows scheduled tasks.
XCOPY fails with an "insufficient memory" error when the path plus filename is longer than 254 characters. An option "/J" copies files without buffering; moving very large files without the option (available only after Server 2008R2) can consume all available RAM on a system.
I too got this error : Insufficient memory
. I found a relevant answer at this link : http://www.terminally-incoherent.com/blog/2007/02/05/xcopy-insufficient-memory/
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.
In conclusion: xxcopy works, but robocopy works even better.
Finally my batch file looks like this
@echo off
ROBOCOPY "H:\Laptop-Backup" "E:\Laptop-Backup" /s
rem /e: Include directories and sub directories even if empty
REM /s Copy Subdirectories, but not empty ones.
The standard Windows command line tools like xcopy, rmdir cannot operate with paths longer than MAX_PATH(260 chars). If you want to remove the directory which contains such file which full path is longer than MAX_PATH, or if you want to copy recursively a directory to such a place where the full path to at least one of its files would be longer than MAX_PATH then these command line tools fail.
However you can bypass it with "move" command line tool, because in distinct to xcopy and rmdir(rd) it seems to not iterating the files in the directory one-by-one. This workaround may be not always convenient and requires additional actions, but for the automation/scripting purpose I don't see any other way if you cannot or don't want using special tools a.k.a robocopy. This way works with a directory, but not with a single file. Let me show an example.
Create a directory. Path length: 245 chars
E:\>mkdir E:\veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongdirectory
Thy to create a file inside it so that the file path length is bigger than MAX_PATH. Usual way it won't work.
E:\>echo "content" > E:\veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongdirectory\longlonglonglonglongfilename.txt
The system cannot find the path specified.
Workaround: Create a file(s) with a short path and move the directory containing the file(s) into the long path.
E:\>echo "content" > somedir\longlonglonglonglongfilename.txt
E:\>move somedir E:\veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongdirectory\
1 dir(s) moved.
Check 1: Was the directory completely moved (with all files)? - Yes.
E:\>dir E:\veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongdirectory\somedir
Volume in drive E is Workspace
Volume Serial Number is C864-7C96
Directory of E:\veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongdirectory\somedir
08/09/2019 11:52 AM <DIR> .
08/09/2019 11:52 AM <DIR> ..
08/09/2019 11:52 AM 12 longlonglonglonglongfilename.txt
1 File(s) 12 bytes
2 Dir(s) 130,574,221,312 bytes free
Check 2. The path is really longer than MAX_PATH, that's why it won't be accessible by the full path for the usual command line tools, so we did everything correct:
E:\>dir E:\veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongdirectory\somedir\longlonglonglonglongfilename.txt
Volume in drive E is Workspace
Volume Serial Number is C864-7C96
Directory of E:\veryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongdirectory\somedir
File Not Found
The same workaround is valid if you want to remove (with rmdir) the directory containing subfolders/files whose path is longer than MAX_PATH. Just move the upper directory to some short temporary location and there you can rmdir it.
NOTE: Windows command line tool "move" can move directories only within the same disk letter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With