Search code examples
batch-fileread-write

Reading from file, Batch


I'm messing around in Batch and I'm wondering...

Can someone help me write to a file (Doc1.txt or Doc1.doc) then read it, set it to a variable. Changed and saved if needed? And have more then one password in a single file?

I've heard it's possible to read to a file, but I can't seem to get it work. I put the following.

FOR /F %i IN (Test1.txt) DO Echo %i

I get the error:

IN is not excepted at this time.

Any help will be loved. Thank you!

For example. Say I was making a log in thingy. Someone can create a new account, make a password, change it, etc etc.


Solution

  • this is relatively simple. use the echo command, set /p, and the less than and greater than signes.

    to save something to a file, do

    echo %variablename%> Filename.extension
    

    to read something from a file into a variable, do

    set /p variablename= < filename.extension