0

I have tried this command and it doesn't work :

...
echo NOTE: if you don't have an account leave it blank
echo Enter the username please
set /p USERNM=Type : 
if USERNM=" " (
echo Added 1000 coins to your account
) >Folder\logs.txt
if else (
echo Added 1000 coins to the account %USERNM% 
) >Folder\logs.txt
...

Let me explain, The Batch-File will ask for the username to save it in a logs.txt file. If the user Don't have an account he will leave it blank and it will display the message above, and if he have one he will enter it and the logs file will include his username, the problem is the code is don't work. If anyone knows Solution please tell me, and Thanks !

Sheep1Man
  • 31
  • 1
  • 8
  • 1
    I would advise you open up a cmd prompt and type:`if /?` to read the help for the IF command. – Squashman Jun 08 '18 at 20:11
  • And in same command prompt window run `set /?` and read also output help for this command. `if "%USERNM%" == " " (` is at least correct syntax. See also [debugging a batch file](https://stackoverflow.com/a/42448601/3074564). And you better read also [How to stop Windows command interpreter from quitting batch file execution on an incorrect user input?](https://stackoverflow.com/a/49834019/3074564) – Mofi Jun 09 '18 at 11:50

1 Answers1

2

Try this:

...
echo;NOTE: if you don't have an account leave it blank
echo;Enter the username please
set /p "USERNM=Type : "
if not defined "USERNM" (
    echo;Added 1000 coins to your account > "Folder\logs.txt"
) else (
    echo;Added 1000 coins to the account %USERNM% > "Folder\logs.txt"
)
...
hXR16F
  • 36
  • 4
  • 1
    Advise `if not defined USERNM (` rather than (*corrected*) `if "%USERNM%" EQU "" (`. Also advise the redirection before the `echo` so the output does not have trailng whitespace .i.e `> "Folder\logs.txt" echo Added 1000 coins to your account`. – michael_heath Jun 09 '18 at 13:30