SCRIPTING - Windows batch-file errorlevel question

I've got a batch file that parses a bunch of file names out of a text file and concatenates them into a single strong - it was previously discussed here. However, I don't want the string to contain a file if the file throw an error when I run it through some command (like a VCS check, for example). Here's my attempt:

set FILE_LIST=
for /f %%x in (temp.txt) do (

:: perform a VCS test
accurev diff -b %%x

:: skip concatenation if error level is > 2
IF errorlevel 2 GOTO NEXT

:: perform the concatenation
set FILE_LIST=!FILE_LIST! %%x

:NEXT
:: print a message if here due to an error above
IF errorlevel 2 echo VCS problem with this file: %%x
)

The problem is - the script appears to stop executing the entire for-loop as soon as it finds one errorlevel greater than 2. If there are five files in the list and the third one has a VCS problem - the script only handles the first two.

This question and answers originated from www.stackoverflow.com
Question by (10/1/2009 9:35:21 PM)

Answer

setlocal ENABLEDELAYEDEXPANSION
set FILE_LIST=
for /f %%x in (temp.txt) do (
    accurev diff -b "%%~x"
    IF errorlevel 2 (
    	echo VCS problem with this file: %%~x
    ) ELSE (
    	set FILE_LIST=!FILE_LIST! %%x
    )
)
Answer by

Find More Answers
Related Topics  scripting  batch-file  errorlevel
Related Questions
  • Batch file ErrorLevel woes

    I am writing a batch file to upgrade some systems. I need to parse a date from an xml file and save it for use later in the file. The format of the date is yyyy\MM\dd. What I have so far is: @…
  • Errorlevel in a For loop (batch windows)

    I have the following windows batch code: for %%i in (iidbms iigcc iigcd dmfacp dmfrcp rmcmd qwerty) do ( tasklist | findstr /i %%i echo %errorlevel% if %errorlevel% == 0 (echo %…
  • Batch ERRORLEVEL results different from CMD?

    Why does ERRORLEVEL behave differently in these two circumstances? From the command line: Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\>aescrypt.exe -…
  • Getting errorlevel from a called batch file

    I have several batch files that I call from a parent batch file. I need to trap if there are any errors that occur in the child batch files. When a child batch file makes a call to an exe file, I am…
  • Why does makensis.exe return errorlevel 1 even though it worked?

    I have a NSIS script that works. It compiles, the produced installer works fine. And yet, makensis.exe returns 1 instead of 0. This is a real pain because I use it in a continuous integration setup …
  • Strange question about windows batch file

    I got 1.txt and 2.txt in my working directory. I use the following batch to list all the files. The batch is this: @echo off for /f "tokens=*" %%a in ('dir *.txt /b') do ( echo -------------…
  • Create event with the batch files

    Here's what i want to achieve. We have this email archive database which we optimize on a weekly basis . At the moment we are manually logging in run the command and monitor the status. The optimiza…
  • TortoiseSVN from the command line and "IF ERRORLEVEL"?

    I have a batch file I'm running from a Windows XP w/service pack 3 workstation which applies SQL changes to a database using sqlcmd.exe in SQL 2005. I've got a command-line entry for TortoiseSVN …
  • How to set ERRORLEVEL in SSIS?

    I have a batch file that runs an SSIS job. I have no knowledge of how the SSIS job runs, I took over a project involving it. The batch file uses %ERRORLEVEL% to detect errors that occur within t…
  • ERRORLEVEL inside IF

    Just stumbled into a weird thing with %ERRORLEVEL% and wanted to see if anyone knows why and if there's a way to fix it. Essentially, it seems as if commands executed inside if statements don't set …