copy user entered text to text file

July 25, 2010 at 08:13:22
Specs: Windows 7
i want to create a batch file that will copy what the user enters in it to a txt file.

in this txt file i have:

server=
nickname=

i want the batch file to copy the user input for server and nickname to the server and nickname lines in the txt file. this text file has other data in it as well.

would i use %variable% - what confuses me is the line position.

thanks in advance, hope i make sense


See More: copy user entered text to text file

Report •


#1
July 25, 2010 at 12:37:42
@ECHO OFF
SET /p server=Server:
SET /p nickname=Nickname:
ECHO %server%>>Name of file.txt
ECHO %nickname%>>Name of file.txt
EXIT

Report •

#2
July 25, 2010 at 17:58:08
thanks matt123, thought that solved it for a second, my text file contains the following data:

[Configuration]
Server=test
WebHost=auto
Nickname=test
[Dynamic]
ServerWarningShown=True

when i used your code it added the entered text at the bottom of the file.

[Configuration]
Server=192.168.0.1
WebHost=auto
Nickname=test
[Dynamic]
ServerWarningShown=True
entered text
entered text 2

i need what ever is entered to replace where the "test" is on server and nickname lines..

thanks.


Report •

#3
July 27, 2010 at 04:59:47
is this do-able?

Report •

Related Solutions

#4
July 27, 2010 at 13:12:49
bumping for answer....

Report •

#5
July 27, 2010 at 15:05:22
Alright, I have an answer for you.

Download SFK and place it in your System32 folder. (C:\Windows\System32\)

Now, here's a code for you:

@ECHO OFF

SET /p Server=Server:
SET /p Nickname=Nickname:

SFK replace 123.txt /Server=/Server=%Server%/ -yes
SFK replace 123.txt /Nickname=/Nickname=%Nickname%/ -yes


Report •

#6
July 27, 2010 at 20:46:54
this works very well, but now if there is already text in the server field it adds to it rather then deletes whats there. same with nickname.

server=previous text
nickname=previous text

run batch file

server=entered text previous text
nickname=entered text previous text

would i have it replace the .txt with one that has a blank server and nickname before anything is entered?


Report •

#7
July 28, 2010 at 14:54:09
Uhmm, I'm not sure if I am able to help you with that.

If you are wanting to save your servers, and have multiple text files, use this:

*Note: I'm assuming that the server addresses are different than the name of the server itself.

@ECHO OFF

SET /p Name=Name Of Server: 

>%Name%.txt ECHO [Configuration]
>>%Name%.txt ECHO Server=
>>%Name%.txt ECHO WebHost=auto
>>%Name%.txt ECHO Nickname=
>>%Name%.txt ECHO [Dynamic]
>>%Name%.txt ECHO ServerWarningShown=True

SET /p Server=Server Address: 
SET /p Nickname=Nickname: 

SFK replace %Name%.txt /Server=/Server=%Server%/ -yes
SFK replace %Name%.txt /Nickname=/Nickname=%Nickname%/ -yes
EXIT

If you aren't wanting to have multiple files with multiple servers, use this:

@ECHO OFF

>FileName.txt ECHO [Configuration]
>>FileName.txt ECHO Server=
>>FileName.txt ECHO WebHost=auto
>>FileName.txt ECHO Nickname=
>>FileName.txt ECHO [Dynamic]
>>FileName.txt ECHO ServerWarningShown=True

SET /p Server=Server:
SET /p Nickname=Nickname:

SFK replace FileName.txt /Server=/Server=%Server%/ -yes
SFK replace FileName.txt /Nickname=/Nickname=%Nickname%/ -yes
EXIT

One of those should work for you!

Let me know.


Report •

#8
July 28, 2010 at 14:58:14
Hey matt123 can you come to batch login to read text file
in this catagorie

Report •

#9
July 29, 2010 at 03:35:49
thanks matt, your a genius, was worried about the sfk.exe, just having to integrate another file, but i can leave it in the directory with the .bat for it to work, it is excellent.

ended up using the second one, works flawlessly as far as i can tell.

thanks for you help.


Report •

#10
July 29, 2010 at 13:46:58
No problem, There might be an easier way to do this, but I'm not sure how. Glad I could help!

Report •

Ask Question