You are not logged in.
Pages: 1
Why this code does not work?
if exist "D:\Test1" if exist "D:\Test2" (
echo OK
) else (
echo Error
)
pause
This code works but I don't know why this extra brace?
if exist "D:\Test1" if exist "D:\Test2" (
echo OK
)
) else (
echo Error
)
pause
Please Help
Offline
Why this code does not work?
if exist "D:\Test1" if exist "D:\Test2" ( echo OK ) else ( echo Error ) pause
This code works but I don't know why this extra brace?
if exist "D:\Test1" if exist "D:\Test2" ( echo OK ) ) else ( echo Error ) pause
Please Help
For what it's worth, your first script works fine for me in Windows XP. The second complains that ") was unexpected at this time."
Offline
What are you trying to achieve? Do you want it only print to print "OK" if both of the files exist?
As intimated by Rekrul, I'm not sure your second code example has been pasted in correctly due to the unbalanced "( )".
I'm guessing maybe you are looking for something like:
if exist "D:\Test1" (
if exist "D:\Test2" (echo OK) else (echo Error)
) else (
echo Error
)
pause
But chaining conditions like this becomes hard to work with as you wind up having to implement your "else" responses repeatedly.
As such, I would structure it more like this:
set "MISSING="
for %%a in ("D:\Test1" "D:\Test2") do (if not defined MISSING if not exist "%%~a" set "MISSING=true")
if "%MISSING%" EQU "true" (echo:OK) else (echo:Error missing file^(s^))
pause
Last edited by bluesxman (17 Dec 2019 09:16)
cmd | *sh | ruby | chef
Offline
Pages: 1