I am making a chat style system in batch for LAN networked computers. I want to check if a username is taken or not and if it is not allow it to be picked, How can I check if what the user inputs in this line (set /p name2=) I have tried this in a test file, but cant get it to work
:startup
set "fail="
set "name2="
set /p "name2=Enter Your Username: "
cls
findstr /b /e /l /c:"%name2%" <"Users.twml" >nul || set fail=1
if defined fail (
goto nope
)
:yes
cls
echo yes, you can use that
echo >> Users.twml %name2%
pause
goto endoftest
:nope
cls
echo thats taken try again
ping locahost -n 3 >nul
goto startup
The issues is it always goes to nope, even if name isn't taken. The Users.twml file is created and if i manually put :Yes where it will load after the user picks name it saves the name to file.
What i want is: user picks name, it checks if its in file(taken) if yes retry with a goto startup, if its not taken, write it to the file and continue on. preferably with a goto section command so i can specify where to go...
The code block above is what i need help with ^^^
The stuff below is what i currently use and it works just no name verification.
Here is the block i currently have for use name selection that is working without the name verification
:startup
cls
echo Pick A UserName
echo 1-16 Character limit.
set /p name2=
if "!name2!" == "" goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if not "!name2:~16!" == "" goto over
REM continues on after name picked if matches above requirements with stuff below
echo >> Connected.twml [System] %computername%:%username% Has joined as: %name2%
echo >> Directory.twml [System] %name2% Has joined the chat.
goto chat
This is what i'm trying to go for to give you a visual idea. And currently is doesn't work
:startup
cls
echo Pick A UserName
echo 1-16 Character limit.
set "fail="
set /p name2=
if "!name2!" == "" goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if "!name2!" == " " goto startup
if not "!name2:~16!" == "" goto over
REM all the above works, now lets try to check if its taken
findstr /b /e /l /c:"%name2%" <"Users.twml" >nul || set fail=1
if defined fail (
goto nope
)
REM continues on after name picked if matches above requirements with stuff below
echo >> Connected.twml [System] %computername%:%username% Has joined as: %name2%
echo >> Directory.twml [System] %name2% Has joined the chat.
echo >> Users.twml %name2%
goto chat
:nope
cls
echo thats taken try again
ping locahost -n 3 >nul
goto startup
This is what the inside of users.twml looks if :yes if ran correctly
username1
username2
username3
username4
@@@@@@@@@@ New edits blow here @@@@@@@@@@@@@@@@
All fixed and working i used %user2% in text file and %name2% in main file so no wonder they dont work together. still dont understand findstr though... This is why you dont write any form of code at 1am with low sleep i guess :)