Avatar of westone
westoneFlag for United States of America asked on

Batch file

I am trying to get the following to work in a batch. Can someone tell me what is wrong with this? I can't figure it out. This section is run by "IF ERRORLEVEL 0 GOTO:Report". Even when the error level is 0 (confirmed by echoing the error level) nothing in this section runs.
Thank You.
If "%TOTAL%" GTR 0 (
		SET SUB="Successful Data Backup"
		SET TXT1="The Data Backup was successful. %TOTAL% new and/or updated file(s) were copied to the encrypted external drive. No Errors were encountered."
	) Else (
	If "%TOTAL%"== 0 (
		SET SUB="Successful Data Backup"
		SET TXT1="The Data Backup ran successfully, however no new or modified files requiring backup were found." 

Open in new window

Windows Batch

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Okay, so ""s indicate string, No ""s indicate number, right?

I'm using this command, which you gave me last night, to copy modified files and set %TOTAL% to the number of files copied:
for /f "tokens=1" %%a in ('xcopy c:\Folder1 e:\Backup /s ^| find "File(s)"') do SET TOTAL=%%a

IF XCOPY in the above command has an error, then the ERRORLEVEL is > 0 and the process jumps to another section to report an error. That should work shouldn't it?

Thanks for all the help.

Yes. Typically the app not sure if XCOPY follows this but

ERRORLEVEL is not to be confused with %ERRORLEVEL%

%ERRORLEVEL% will only ever have 1 number. Not necessarily 1 when there is an error but ERRORLEVEL 1 will always (since I've been using it) be set when there was an error.
Your help has saved me hundreds of hours of internet surfing.