tags:

views:

128

answers:

2
@echo off
set filename = 
cd GWConfig_TDS-mtpe3003
set filename = VCU17_CCU6\applications\VCU17APP 
GOTO CHECKFILE

:CHECKFILE 
echo reached
IF EXIST %filename% ( echo exists 
) ELSE ( echo Doesnot exist )

/////////////////////////////////////////////////

Here output shows :

reached

Doesnot echo "exists" or "Doesnot exist"

Is there anything wrong with the use of variable "filename".

Also,

@echo off
set filename = 
cd GWConfig_TDS-mtpe3003
set filename = VCU17_CCU6\applications\VCU17APP 
GOTO CHECKFILE

:CHECKFILE 
echo reached
IF EXIST VCU17_CCU6\applications\VCU17APP ( echo exists 
) ELSE ( echo Doesnot exist )

gives output:

reached
exists.
+2  A: 

There are two problems here. One is the space after the variable name:

SET filename = whatever

should be

SET filename=whatever

(Or you could use %filename % later, but that's just horrible :)

The second problem is that without any quotes, your "IF" test won't work properly if %filename% is empty. Quote it instead:

IF EXIST "%filename%" ( echo exists
) ELSE ( echo Doesnot exist )
Jon Skeet
Thank u Jon !!!!!!!!!!!!!!
Yuck, indeed, the variable name has a trailing space. That's just awful. I banish spaces around `=` out of habit, never noticed that it has consequences for the variable name too.
Joey
+1  A: 

I don't have the time to properly re-create this now, but I can spot a few potential problems:

  • Have you tried removing the spaces around the = in set:

    set filename=VCU17_CCU6\applications\VCU17APP
    

    otherwise you might have a single space leading your file name

  • You might want to try to quote the use of %filename%:

    IF EXIST "%filename%" ( ...
    
Joey