1

I have a batch script in which i am using multiple if exist statement, the problem is all statements are working except one .

Following variables are set

SETLOCAL ENABLEDELAYEDEXPANSION
SET basedrive=E:
SET tfworkspace=!basedrive!\TFS
SET envdefault=%1
SET projenv=!envdefault!
echo subapp=!subapp! subappservice=!subappservice! 
SET tfworkspacepath=!tfworkspace!\!releasebranch!\!app!\!subapp!

This statement works,

if exist "!tfworkspacepath!" (robocopy "!tfworkspacepath!"\sourcecode\messagebroker\ /E /NFL /NJS /NDL /ETA  "!basedir!\!messagebroker!" )  else SET /a foldererror=1
SET tfworkspacepathservice=!tfworkspace!\!releasebranch!\!app!\!subapp!\sourcecode\build\!projenv!

This statement doesn't work, by does not work i mean even thou the path does not exist it it still tries to robocopy.

if exist !tfworkspacepathservice! (
  robocopy !tfworkspacepathservice! /E /NFL /NJS /NDL /ETA  "!basedir!\!scripts!") else  SET /a foldererror =!foldererror!+1

I am new to batch writing, please guide me

akash
  • 333
  • 1
  • 10
  • Welcome to batch scripting, aka hell. Can you switch to a modern scripting language like PowerShell? Makes things so much easier. – Mark Henderson Jun 11 '14 at 02:37
  • @Mark business limitation is to use batch, otherwise i can moderately code this stuff well in vbs. – akash Jun 11 '14 at 02:38

1 Answers1

0

First of all my apologies to everyone who came here trying to help.

what was wrong ?

i had an if statement which verifies a subappservice variable if it is empty, syntax wise it was imperfect.see the BAD syntax below

if NOT !subappservice!=="" (SET scripts=!scripts!\!subapp!) else SET projenv=!projenv!\!subappservice!& SET scripts=!scripts!\!subapp!\!subappservice!

i corrected it to below to fix the problem

if [!subappservice!]== []  (SET scripts=!scripts!\!subapp!) else SET projenv=!projenv!\!subappservice!& SET scripts=!scripts!\!subapp!\!subappservice!

my take - even thou syntax was bad or imperfect CMD.exe does not issue any warning and i kept on validating my script until i found this accidently. i am putting it here so that someone else can benefit from my mistake :)

akash
  • 333
  • 1
  • 10