Ms Dos Copy Error Codes
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow copy errorlevel Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow dos copy return codes is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Windows copy command return xcopy exit code 4 codes? up vote 18 down vote favorite 3 I would like to test for the success/failure of a copy in a batch file, but I can't find any documentation on what if any errorlevel codes are returned. For example copy x y if %errorlevel%. batch file xcopy error handling eq 1. ( echo Copy x y failed due to ... exit /B ) else ( if %errorlevel% eq 2. ( echo Copy x y failed due to ... exit /B ) ... etc ... ) windows batch-file share|improve this question asked Nov 21 '11 at 21:55 Bill Ruppert 5,34671540 add a comment| 4 Answers 4 active oldest votes up vote 25 down vote accepted I'd opt for xcopy in this case since the error levels are documented (see xcopy documentation, paraphrased below): Exit code Description ====
Xcopy Invalid Number Of Parameters
=========== 0 Files were copied without error. 1 No files were found to copy. 2 The user pressed CTRL+C to terminate xcopy. 4 Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line. 5 Disk write error occurred. In any case, xcopy is a far more powerful solution. The equivalent documentation for copy does not document the error levels. As an aside, you may want to rethink your use of the %errorlevel% variable. That has nasty ramifications (at least in some versions of Windows) if someone has explicitly done something silly like: set errorlevel=22 In those cases, the actual variable will be used rather than grebbing the actual error level. The "normal" way of doing this is (in decreasing order since errorlevel is a "greater than or equal to" check): if errorlevel 2 ( echo Copy x y failed due to reason 2 exit /B ) if errorlevel 1 ( echo Copy x y failed due to reason 1 exit /B ) If you are running Win7 or Win Server 2008 or later, you should look into Robocopy, which is now the preferred mass-copy solution.. share|improve this answer edited Dec 10 '13 at 12:45 Ghyath Serhal 4,88432749 answered Nov 21 '11 at 22:05 paxdiablo 491k1189731422 3 It is easier to do that checking this way: for %%e in (5 4 3 2 1) do if errorlevel %%e goto reason-%%e followed by echo Copy OK –Aacini Nov 22 '11 at 0:48 1 @H
command or file name Bad or missing command interpreter Cannot perform a cyclic copy Divide overflow Drive not ready Duplicate file name or file not found File cannot be copied onto itself File creation error File not
Xcopy Parse Error
found General Failure Insufficient disk space Internal stack overflow Invalid directory Invalid drive specification Invalid xcopy arguments file name or file not found Invalid media, track 0 bad or unusable Invalid number of parameters Invalid parameter Invalid Switch Non-System disk xcopy file or directory or disk error Not ready, reading drive X Parse error The system cannot find the drive specified The system cannot find the file specified The system cannot find the path specified Write fault error Write protect A http://stackoverflow.com/questions/8219040/windows-copy-command-return-codes duplicate file name exists, or the file cannot be found When attempting to rename a file, the file does not exist or there is already a file with that name. Verify no other file exists with the same name in the current directory and that you're typing the file you want to rename correctly. How to change or rename a file, folder, or directory. Abort, Retry, Fail? This error is commonly encountered when attempting to read http://www.computerhope.com/doserror.htm a diskette that is not readable or if no disk or disc in the drive trying to be read. Unable to read floppy diskette. CD-ROM receiving power but does not work. Access denied In new versions of Windows Vista, Windows 7, Windows 8, and Windows 10 if you do not run the Windows command line in an elevated mode you will get "Access denied" errors when running a command. See our elevated mode for information about this mode and how to enter the mode. or Access dened can also be caused when a file or directory has read-only attributes, is being modified by another person or program, or other permissions preventing the action. See the attrib command for further information and options on this command. Bad command or file name Caused by a misspelling or error when typing a command or when the command attempting to be used is not a valid command for your version of MS-DOS or Windows. See our file name page for information about files, file name examples, and a list of invalid characters. Bad or missing command interpreter The computer cannot locate the command.com (command interpreter), an important file that enables the computer to boot into the operating system. Receiving error "Missing command interpreter." Cannot perform a cyclic copy This error occurs when you're trying to copy or xcopy all direc