Somewhere i a batch file i have a piece of code that checks if a directory exists. If not then ask the user what to do. Now the strange thing is then when the directory exists i still get the question "Do you want to create the directory?" which is inside the if statement.
What am i missing here?
cls
@echo off
SET PanterPath="W:\Windows\Panther\"
if NOT exist %PanterPath% (
echo Directory %PanterPath% not found! Cannot copy and apply unattend file.
SET /P var=Do you want to create the directory? (Y/N)
if /I "%var%" EQU "Y" (
echo Creating directory %PanterPath% ...
mkdir %PanterPath%
) else (
echo Directory %PanterPath% not created so script cannot continue. The image deployment failed!
pause
exit
)
)
pause
pause
EDIT When i add a else statement to the If Exists
then the output is:
Directory "W:\Windows\Panther" found
Directory "W:\Windows\Panther" not created so script cannot continue. The image
deployment failed
Press the any key...
Code:
SET PanterPath="W:\Windows\Panther"
If Exist "%PanterPath%\" (
echo Directory %PanterPath% found!
) else (
echo Directory %PanterPath% not found! Cannot copy and apply unattend file.
SET /P var=Do you want to create the directory? (Y/N)
if /I "%var%" == "Y" (
echo Creating directory %PanterPath% ...
mkdir %PanterPath%
) else (
echo Directory %PanterPath% not created so script cannot continue. The image deployment failed!
pause
exit
)
)
pause
pause