Search code examples
windowsbatch-fileloggingdos

I need to log a certain snippet of information in a batch file, and I don't know how


Okay so I am currently creating a Artificial Intelligence program (VERY basic), and I need to be able to log the name inputted by the user. I don't understand from other articals posted. Here's the area of code:

set /p input= Before we talk, I'd like to ask your name so I can properly address you. Please print your name.
set /p Name= 

As you can see here, we have an input area and I need the file to save the inputted text, and re-open the file and use the name, every time you go onto this program. Thanks in advance for any help!


Solution

  • @echo off
    setlocal EnableDelayedExpansion
    
    call :GetName
    if not defined Name (
       echo Before we talk, I'd like to ask your name. Please print your name.
       set /p Name=
       echo set "Name=!Name!" >> "%~F0"
    ) else (
       echo Hello %Name%, I am glad to see you again.
    )
    
    rem The rest of the code goes here...
    
    
    goto :EOF
    
    rem Be sure that the next is the last line in this file:
    :GetName