Re: Xcopy behavior questions

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: David Candy (david_at_mvps.org)
Date: 04/27/04


Date: Wed, 28 Apr 2004 06:15:06 +1000

The following list shows each exit code and a brief description of its
meaning:

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.

from Dos 6.22 help file which is the best reference for exit codes.

-- 
----------------------------------------------------------
http://www.g2mil.com/Dec2003.htm
"Michael D. Ober" <obermd-.@.-alum-mit-edu-nospam> wrote in message news:eOBwAAJLEHA.3904@TK2MSFTNGP09.phx.gbl...
> I used %errorlevel% in MS-DOS 5.  You have to check your errorlevels in
> descending order as the example below shows.  That said, there may be a bug
> in XCOPY.  Also, MS never really documented the error levels returned by
> their utilities.
> 
> Mike Ober.
> 
> "Stephen Quist" <quists@spamfree.msei-co.com> wrote in message
> news:%23R$d7wILEHA.2260@TK2MSFTNGP09.phx.gbl...
> > Thanks for the suggestions.
> >
> > Is it true that the %errorlevel% usage is an NT improvement that is not
> > available under Win98?
> >
> > Apparently, despite the clear statement in the help for Xcopy,
> > it never, under any circumstances, returns an errorlevel of 1.
> > Pity. I, for one, would find it useful.
> >
> > Steve
> >
> >
> >
> > Al Dunbar [MS-MVP] wrote:
> > :: "Stephen Quist" <quists@spamfree.msei-co.com> wrote in message
> > :: news:%23J1GFLaIEHA.3144@TK2MSFTNGP10.phx.gbl...
> > :::
> > ::: Major Ninth wrote:
> > ::::: did you use ERRORLEVEL or %ERRORLEVEL% ?
> > ::::: -john
> > :::::
> > ::: I used the standard syntax.
> > ::
> > :: Seems like standard DOS-based batch syntax - see suggestions below...
> > ::
> > :::    I've tried it with nonexistent directories
> > ::: and empty directories. None of my tests gave me an errorlevel of 1.
> > ::: Here's my test file:
> > :::
> > ::: @setlocal
> > ::: if %1. == . goto needdir
> > ::
> > :: or:
> > ::
> > ::     if "%1" EQU "" goto:needdir
> > ::
> > ::: @if exist i:\not_now.text goto notnow
> > :::
> > ::: xcopy i:\esprel %1 /r /c /l /d /exclude:i:\esprel\excludelist.txt
> > ::: temp.txt
> > ::
> > :: or replace these lines:
> > ::
> > ::: @if errorlevel 5 goto e5
> > ::: @if errorlevel 4 goto e4
> > ::: @if errorlevel 2 goto e2
> > ::: @if errorlevel 1 goto e1
> > ::: @if errorlevel 0 goto e0
> > :::: e5
> > ::: @echo errorlevel 5
> > ::: @goto end
> > :::: e4
> > ::: @echo errorlevel 4
> > ::: @goto end
> > :::: e2
> > ::: @echo errorlevel 2
> > ::: @goto end
> > :::: e1
> > ::: @echo errorlevel 1
> > ::: @goto end
> > :::: e0
> > ::: @echo errorlevel 0
> > ::: @goto end
> > ::
> > :: with these lines:
> > ::
> > ::     @echo errorlevel is %errorlevel%
> > ::     @goto:eof
> > ::
> > :::
> > :::
> > :::: needdir
> > ::: @echo off
> > ::: @echo test message
> > ::: @goto end
> > :::
> > :::: notnow
> > ::: @type i:\not_now.text
> > :::
> > :::: end
> > ::
> > :: Don't need a :end label, as :eof is implicitly there.
> > ::
> > :: /Al
> >
> >
> 
> 


Relevant Pages

  • Re: Xcopy behavior questions
    ... The following list shows each exit code and a brief description of its ... from Dos 6.22 help file which is the best reference for exit codes. ... > I used %errorlevel% in MS-DOS 5. ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: Xcopy behavior questions
    ... XCopy is one of the rare ones in the XP help file. ... It's identical to Dos. ... > The following list shows each exit code and a brief description of its ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: Xcopy behavior questions
    ... XCopy is one of the rare ones in the XP help file. ... It's identical to Dos. ... > The following list shows each exit code and a brief description of its ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: "FFIND" Exit Codes?
    ... Steve Fabian wrote: ... || and to issue exit code `0' if it finds any, `1', if it does not. ... | IF ERRORLEVEL 1 GOTO NO-NEW-FILES ... quite possible that FFIND never sets the errorlevel. ...
    (comp.os.msdos.4dos)
  • Re: System.Diagnostics.Process / .BAT file / always returns exit code 0
    ... distinguishing DOS "errorlevel" vs. process return code. ... to suspect that if I set "errorlevel" in a .BAT file, ... Good suggestion on writing a program to return the exit code; ...
    (microsoft.public.dotnet.languages.csharp)