Computing.Net > Forums > Windows XP > DOS file append

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

DOS file append

Reply to Message Icon

Name: dachadster13
Date: November 4, 2009 at 05:38:01 Pacific
OS: Windows 7
Subcategory: Configurations
Tags: DOS command
Comment:

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?



Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: November 4, 2009 at 06:03:25 Pacific
Reply:

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.


0

Response Number 2
Name: dachadster13
Date: November 4, 2009 at 13:10:16 Pacific
Reply:

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.


0

Response Number 3
Name: Mechanix2Go
Date: November 4, 2009 at 22:42:04 Pacific
Reply:

You need tobe clear about:

Does the original have blank lines?

Where is the new stuff to be inserted?


=====================================
Helping others achieve escape felicity

M2


0

Response Number 4
Name: dachadster13
Date: November 5, 2009 at 04:54:12 Pacific
Reply:

Here is where I need to be able to insert the text:

x= original text in file

xxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxxxxxx
my new text

xxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxx

Sorry for the confusion.


0

Response Number 5
Name: ace_omega
Date: November 5, 2009 at 06:58:15 Pacific
Reply:

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
  )

Reference:

http://commandwindows.com/batchfile...
http://www.robvanderwoude.com/ntfor...


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: DOS file append

DOS files www.computing.net/answers/windows-xp/dos-files/27037.html

cant delete DOS files on XP comp www.computing.net/answers/windows-xp/cant-delete-dos-files-on-xp-comp/76822.html

bootable cd with all 125 dos files www.computing.net/answers/windows-xp/bootable-cd-with-all-125-dos-files/146446.html