View Single Post
Old 06-23-2008   #4 (permalink)
Reventlov


 
 

Re: Howto: Add lines of text from a specific point in a text file..

Il giorno Mon, 23 Jun 2008 01:55:59 -0700 (PDT), Daz <darren.blackley@xxxxxx> ha
scritto:
Quote:

>Hi all,
>
>I wonder if you can help me... I have been doing allot of manual
>updates to ini files that i am using and would like to make things a
>little easier on myself by trying to automate as much as i can. What
>i need at the moment is a way of adding some addition text to a file
>that already exists - the catch is that i need to add it to the end of
>a group of information and that information starts around the middle
>of the file. E.g. below.
This renames the file to .bak, reads it and writes it with the original name. When it
reads Yoursection writes additional data.


percorso="C:\mydir\myfile.txt"

Const ForReading = 1 'Open a file for reading only. You can't write to this file
Const ForWriting = 2 'Open a file for writing
q= chr(34) 'virgolette
Set fso = CreateObject("Scripting.FileSystemObject")
on error resume next
fso.DeleteFile percorso & ".BAK"
on error goto 0
fso.MoveFile percorso ,percorso & ".BAK"
set source = fso.OpenTextFile(percorso & .BAK",ForReading)
set dest= fso.OpenTextFile(percorso ,ForWriting,TRUE)
Do While source.AtEndOfStream <> True
riga = source.ReadLine
if instr(1,riga,"[yoursection]")>0 then
dest.writeline "[yoursection]" & vbcrlf & "................"
else
dest.writeline riga
end if
Loop
source.Close
dest.close

End Sub


--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--
My System SpecsSystem Spec