recently I have been trying to use batch files to do some repetitive work for me, and checking whether a file exist within a current directory is crucial. I have worked with batch files often in the past, but I am now using a new computer, and the old batch files I obtain from dropbox does not work, and I am unsure why. Consider a batch script:
@echo off
echo Build Verification...
if not exist "%cd%\build.bat" GOTO buildFail
echo Success!
pause
exit
:buildFail
echo Building of mod failed!
pause
exit
build.bat DOES exist, in the current directory, but this is what the cmd gave me:
Build Verification...
The syntax of the command is incorrect.
Building of mod failed!
Press any key to continue...
Baffled at why this would happen, I tried a few variation:
(In case dynamic directory has problems)
@echo off
echo Build Verification...
if not exist "%~dp0\build.bat" GOTO buildFail
echo Success!
pause
exit
:buildFail
echo Building of mod failed!
pause
exit
But it yield same results
Directly copying the directory wholesale without using %dp~0 or %cd% also yields the same result.
By setting the directory as a variable does not work either:
set randdir = "%cd%\build.bat"
if not exist "%randdir%" GOTO buildFail
But here is the weirdest part: Calling the catch file works
@echo off
echo Build Verification...
call "%cd%\build.bat"
This would result in the activation of build.bat
Please help!