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.
1
  • Did you try SET without spaces around the =? I don't know if dos understands whitespaces here :) Commented Sep 7, 2009 at 8:44

2 Answers 2

6

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 )
Sign up to request clarification or add additional context in comments.

1 Comment

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.
2

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%" ( ...
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.