DOS file append

November 4, 2009 at 05:38:01
Specs: Windows 7
I am trying to simplify the process of editing an .ini file for a proprietary software company. I know how to append text to a file which already exists but I was wondering if there was a way to specify the entry point of that text. Meaning, instead of simply adding to the end of the already existing text, directing it somewhere in the middle?

See More: DOS file append

Report •

November 4, 2009 at 06:03:25
You can't do that directly. If you are using a batch script (note, by the way, this is not "DOS command" - there is no DOS in Windows 7, it's called the Win32 Command Processor and differs significantly from DOS) you will have to use a FOR /F statement to read the file line-by-line and write each line to a new file, until you get to where you want, then append the lines you want, then continue from where you left the file to add the remaining lines into the new file. Then delete the old file and rename the new one.

If you use a proper programming language, you can open the file in read+write mode, seek to the middle of the file, read and save the contents from there to the end, then seek back to the middle of the file, write the new content, and then write the saved content to the end.

Report •

November 4, 2009 at 13:10:16
Sorry for the confusion but this would be on a system running
Windows XP Pro SP2. I will look into the above mentioned for
/f statement but if there is a different way to approach this in
XP, please let me know. Thank you for all your help.

Report •

November 4, 2009 at 22:42:04
You need tobe clear about:

Does the original have blank lines?

Where is the new stuff to be inserted?

Helping others achieve escape felicity


Report •

Related Solutions

November 5, 2009 at 04:54:12
Here is where I need to be able to insert the text:

x= original text in file


my new text


Sorry for the confusion.

Report •

November 5, 2009 at 06:58:15
Again post this in the programming forum.

Its not specific enough. We need key words to mark where you want to start entering the text or at the very least the number of lines down.

To do this you could do some thing like...

@echo off
set KeyText = "Bla"
set TextToInsert = "Bla Bla Bla"
echo y|del newfile.txt

For /F "tokens=*" %%A in ('type yourfile.txt') do (
  echo %%A >> newfile.txt
  if "%%A" == "%KeyText%" then echo %TextToInsert% >> newfile.txt


Report •

Ask Question