So I currently creating a program that hide a files and moving it to other places, and to retrieve the file you need to put the password. But i found a problem where when i only press ENTER and not putting a password, the batch program closed. I wanted to make it so that when you press ENTER or not putting a password it says "Please enter the password!" until it gets what it wanted. (to be honest this is just something that i googled and copy paste, and change it a little)
Additional question, is it fine to use
set /p "something=>"
instead ofset /p something=
Here is the commands and codes that i used.
I know that this is complicted and might be the worst thing to write.
@ECHO OFF
title unlock the stuff
if EXIST SecretCodes goto CONFIRM
if NOT EXIST SecretCodes goto CONFIRMATION
:CONFIRM
echo are you sure you want to Lock the stuff?(Y/N)
set /p "cho=>"
if %cho%==Y goto LOCK
if %cho%==y goto LOCK
if %cho%==n goto END
if %cho%==N goto END
echo excuse me?
goto CONFIRM
:LOCK
move /-Y C:\Users\MyName\Desktop\SecretCodes C:\Users\MyName\AppData\Roaming\Hidden
attrib +H +S C:\Users\MyName\AppData\Roaming\Hidden\SecretCodes
echo Secret is locked!! o7
pause
goto END
:UNLOCK
title Unlock
echo Please enter the password!
set /p "pass=>"
if NOT %pass%== passwordispassword goto FAIL
move /-Y C:\Users\MyName\AppData\Roaming\Hidden\SecretCodes C:\Users\MyName\Desktop
echo the secret has been revealed!
pause
goto END
:FAIL
title Unlock
set /p "pass=>"
if NOT %pass%== passwordispassword goto END
move /-Y C:\Users\MyName\AppData\Roaming\Hidden\SecretCodes C:\Users\MyName\Desktop
echo the secret has been revealed!
goto END
:CONFIRMATION
echo are you sure you want to Unlock the secrets?(Y/N)
set /p "choo=>"
if %choo%==Y goto UNHIDE
if %choo%==y goto UNHIDE
if %choo%==n goto END
if %choo%==N goto END
echo excuse me?
goto CONFIRMATION
:UNHIDE
attrib -H -S C:\Users\MyName\AppData\Roaming\Hidden\SecretCodes
goto UNLOCK
to makes things more clearer, in the codes that i write :
:CONFIRM
echo are you sure you want to Lock the stuff?(Y/N)
set /p "cho=>"
if %cho%==Y go to LOCK
if %cho%==y goto LOCK
if %cho%==n goto END
if %cho%==N goto END
echo excuse me?
goto CONFIRM
, will make me repeat the command if i put the wrong input for example i type E and then enter. It will say "excuse me?" and then asking again "are you sure you want to Lock the stuff?(Y/N)", the problem that i'm getting is when i put nothing (press Enter immediately...). when i put nothing into it, the cmd will close.
So going back to question number 1, is there a way to prevent cmd closing from pressing the enter button and not put any password on the input?