Link to home
Start Free TrialLog in
Avatar of jasont09
jasont09

asked on

Merge Text Files At Exact Point

Hi

I am trying to merge to text files in a folder. At the moment the newest file (1) in the folder gets appended to the end of the oldest file (2). (there are only to files in this folder)

The text files are templates and within the oldest file (2) I have 7 breakpoints highlighted by @*#*@

My Aim is to insert file (1) before the 5th occurence of @*#*@

The current code I was using is fairly old and is in asp vbscript,

dim fs,fo,x
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder("D:\sites\")
set combinedFile=fs.CreateTextFile("D:\sites\export.txt",true) 

for each x in fo.files
  set fil = fs.getFile("D:\sites\" & x.Name) 
  if fil.size > 0 then
	Set f=fs.OpenTextFile("D:\sites\" & x.Name)
	combinedFile.WriteLine(f.ReadAll)
  end if
  set f = nothing
  set fil = nothing
next

set fo=nothing
set fs=nothing

Open in new window


So rather than appending the 2nd file at the end of the 1st file, it will merge it and keep the end of the 1st file in tact.

Help much appreciated
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jasont09
jasont09

ASKER

Outstanding! Thank you very much... You really have just put a big beaming smile on my face, i've been playing around with this for the past couple of hours, your code worked 1st time.

Thanks again
No problem.  Thanks for the grade.

Regards,

Rob.