Replace text in TXT file using .bat

February 24, 2011 at 09:30:11
Specs: Windows 7
i have a text file that i want to edit based on used input

contents of txt-

the location of the saved document is C:\test\word.doc

what i want it to read

the location of the saved document is C:\Document\word.doc

code i have so far -

@echo off
set DIRNAME=
:input_DIRNAME
set /P DIRNAME=Enter Director Name: %=%

so the above gets my user input c:\%DIRNAME%\word.doc

but how do i add to txt doc with out deleting the rest??

thanks for any help


See More: Replace text in TXT file using .bat

Report •

#1
February 24, 2011 at 11:30:28
use a double > insted of only 1 > so if you want to create a txt doc you say:
echo. what am I doing >File.txt
if you want to replace this text you also use >File.txt
If you want to add text to the original document: What have I done now >>File.txt
In this case File.txt will read:
What am I doing
What have I done now

D_Pikster


Report •

#2
February 26, 2011 at 20:58:21
I guess what you want is to get the folder name from user and then save c:\%DIRNAME%\word.doc as new location in your text file..

if so then try this or be more a bit more clear on what you want.


+++++++++++++++++++++++++++++++++++++++++++++
@echo off
set DIRNAME=
:input_DIRNAME
set /P DIRNAME=Enter Director Name:
echo the location of the saved document is C:\%DIRNAME%\word.doc
echo the location of the saved document is C:\%DIRNAME%\word.doc >yourtextfilename.txt
+++++++++++++++++++++++++++++++++++++++++++++++++++++++


It will put "the location of the saved document is C:\%DIRNAME%\word.doc" in your text file...

Subhash Chandra.


Report •
Related Solutions


Ask Question