how can a batch file be written to remember text from the previous time it was run?

such as if i were to input:"hello ow are you" could the batch file remember this line the next time it was run even if it was a year later...

sort by: active | newest | oldest

I use .txt files, for example, here is a program called Name.bat that when ran it will ask you for your name, then the next time its ran it will tell you your name as you previously entered in its past run:

@echo off

if exist name.txt (

set /p name<name.txt

echo Your Name Is %name%!



if not exist name.txt (

echo Hi! Whats Your Name?

set /p name=Name:

@echo %name%>name.txt



orksecurity7 years ago
Short term, environment variables. Longer term, use the variable value to build a second batch file which sets an environment variable, and have this batchfile call the other. Better answer: Switch from batchfiles to a more serious language.
Hey man, he asked how to do this in batch. Please answer in batch, otherwise don't answer, because I get that a lot, the "Batch is seriously not a language."
Psychic Master (author)  orksecurity7 years ago
could you give a more serious language that is easy to learn?
batch isn't even a language...although i do get you're point, Batch is a highly useful tool...
g-one7 years ago
Try this batch code. It will write inputs in the own file. Note that the number behind the option "skip" is the count of lines of the actual batch code.

@echo off &setlocal
for /f "skip=7 tokens=*" %%i in ('type "%~0"') do set "txt=%%i"
if defined txt echo Your last input was "%txt%".
set /p "x=Your new Input: "
if defined x echo %x%>>"%~0"
goto :eof
lemonie7 years ago
You're stretching things a bit here (as other comments). A batch file is just a list of commands, it's not a programming language. L
AndyGadget7 years ago
You need to use redirection which is telling a command to take its input or send its output to a device (or file) other than the screen or keyboard.

Simplest form ;-

echo Hello how are you > hello.txt
type hello.txt

Using > overwrites an existing file.
Using >> appends (sticks it on the end) an existing file (creates it if necessary).