Author Options:

Add text into a batch file Answered

Can somebody tell me if you can add text into a batch file at a specific point.
When i add text (with another batch file) it always go's to the end of the text/batch file. That does not help having the text at the bottom like this

echo hello

for example
when I want to add text like this

echo hello

at the moment I use this code to add text to a batch file

pushd %CD%
for %%j in (1.bat) do type "%%j" >> 2.bat

Thanks in advance
If you don't understand please comment and say what you don't understand :)


Are you trying to modify a batch file that has been saved to a file already? And are you trying to add a new command line into the existing batch code?

Usually you would want to know beforehand all of the actions that you might want to do and program that into the batch file.  You could pass on parameters or test conditions to execute a certain action.

You could concatenate and append files but maybe there is a utility out there that acts like a character substitution function that can place something in a certain position if you tell it where to.  Good luck.

Thats exactly what i'm trying to do


.  It's been so long since I used BAT files that I'm not sure this will work, but ...
.  If I wanted to insert a new line at line X of the file, I would read lines 1 through (X-1) from the original file and write them to the destination file. Then append new line to destination file. Then read lines X to EOF from original file and append to destination file. Delete original file. Rename destination file.
.  Or read lines 1 to (X-1) into a variable. Append new line to variable. Append lines X to EOF to variable. Write variable to destination file. Delete orig. Rename dest.
.  Or read the whole file into a var, write lines 1 through (X-1), ...