|Hello guys, |
I've been trying to write some code using dos commands, and i've been facing this strange
issue.The requirement is to check if a certain folder exists, and if it does, the user
would be given a choice to either overwrite the folder or leave it as it were.
I've written the following code to achieve the above:
IF EXIST C:\TEST (
@ECHO A DIRECTORY WITH THE SAME NAME "C:\TEST" ALREADY EXISTS.
SET /P USERINPUT="DO YOU WANT TO OVERWRITE THE EXISTING DIRECTORY (Y/N):"
) ECHO %USERINPUT%
The issue is, when I run this script multiple times, the value of the input variable %
USERINPUT% seems to persist.
For instance, if this script is run for the first time and user input is "y", the variable
%USERINPUT% echoes "y". Now if the script is run a second time on the same command window,
and the user input is "n", the variable %USERINPUT% still echoes "y". If this script is run
a third time, and one enters a "y", the variable %USERINPUT% would echoes a "n".
It thus seems that the vaue in the variable %USERINPUT% presists for a longer duration,
which is obvious not the desired result.
Could anyone throw any light on this issue? I need to get this to work so as to accept the
right values. I'am not sure what the issue is here.