edman747MemberAug 31, 2007 at 8:30 am #127536
This problem seems to lend it self to scripting. can usually find parts of other examples and workout the syntax, when I have figured out what to do.
background and problem description:
have a group of files, approximately 300. that need to be updated.
each compiled file has a text file embedded in it. will pre-process each to extract the text file.
Each text file to be searched for multiple items. two lines should be inserted after each match. a counter should be kept to indicate the total number of items found. then each file will have a block of several lines of text appended to the end of the file. with the value of the counter included in the block.
description of the steps:
preprocess each file to export the text. (ent file)
this involves calling an external program to process each file. no problems here.
define a set of items (“item1”, “item2”, “item3”)
stuff1 is two lines of text to be inserted.
stuff2 is a group of lines to be appended to the end of the file.
open a text file.
search for an item in the set.
when a match is found
increment the counter, insert two lines. (stuff1)
search for the next item.
if any items are found append stuff2 to the end of file.
stuff2 includes the value of the counter.
[manual verification of links in updated text files]
postprocess to import the updated ent file. no problem.
now the question: where to start?
here is what I have used for search and replace text in other files. not sure how to insert a line of text after finding a match. Or the second part about appending text to the end of the file. maybe close the file and reopen for append?Code:Dim f, fc, afile
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set f = objfso.GetFolder(“.”)
Set fc = f.Files
For Each aFile In fc
‘If UCase(Right(aFile.Name, 3)) = “CFG” then
If Left(afile.Type, 3) = “CFG” Then
Set objFile = objFSO.OpenTextFile(afile, ForReading)
strText = objFile.ReadAll
strNewText = Replace(strText, “mp_multiplespawn 0”, “mp_multiplespawn 1”)
Set objFile = objFSO.OpenTextFile(afile, ForWriting)
if anyone can help me get started, thanks.
You must be logged in to reply to this topic.