Batch file - using a variable
@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 the output shows:
reached
Does not exist echo "exists" or "does not exist"
Something is wrong with the "filename" variable.
Besides,
@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 the result:
reached
exists.
There are two problems here. The first is a space after the variable name:
SET filename = whatever
it should be
SET filename=whatever
(Or you can use it %filename %
later, but that's just awful :)
The second problem is that without any quotes, your "IF" test will not work as expected if %filename%
empty. Instead of this:
IF EXIST "%filename%" ( echo exists
) ELSE ( echo Doesnot exist )
source to share
I don't have time to recreate this correctly now, but I can spot several potential problems:
-
Have you tried removing spaces around
=
inset
:set filename=VCU17_CCU6\applications\VCU17APP
otherwise you can have one space leading to your filename
-
You might want to quote the usage
%filename%
:IF EXIST "%filename%" ( ...
source to share