Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editing Text Files using VB Script

Status
Not open for further replies.

Howlingmad

IS-IT--Management
Dec 23, 2004
9
0
0
GB
Do your files really look like this, or are you showing this for illustrative purposes? The reason I ask is because there are many possible answers to the question depending on the actual structure of your data.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
No sorry it doesn't i'd post the real files but they have banking info in them. What i can tell you is that the character i want to get rid of is on the last line of the first file and it is the only character on that line. The file is never has the same information in it and the amount of lines change. Hope this helps
 
In that case, the way that I would do it is this:

Code:
Option Explicit

Const vbForReading = 1
Const vbForWriting = 2
Const vbForAppending = 8

Dim oFSO:Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim oFile1
Dim oFile2
Dim oResFile
Dim strCombinedString

Set oFile1 = oFSO.OpenTextFile("TestFileOne.txt", vbForReading)
Set oFile2 = oFSO.OpenTextFile("TestFileTwo.txt", vbForReading)

strCombinedString = MyCombineFiles(oFile1, oFile2)
Set oResFile = oFSO.CreateTextFile("Results.txt", True)
oResFile.Write strCombinedString

Set oFile1 = Nothing
Set oFile2 = Nothing
Set oResFile = Nothing
Set oFSO = Nothing

Function MyCombineFiles(oF1, oF2)
	Dim i
	Dim arr()
	
	i = 0
	Do While Not oF1.AtEndOfStream
		ReDim Preserve arr(i)
		arr(i) = oF1.ReadLine()
		i = i + 1
	Loop
	For i = 0 To UBound(arr) - 1
		MyCombineFiles = MyCombineFiles & arr(i) & VbCrLf
	Next
	MyCombineFiles = MyCombineFiles & oF2.ReadAll()
End Function

When TestFileOne.txt is:
x

And TestFileTwo.txt is:
x

Then Result.txt is:
x

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Thank you very much it worked like a charm!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top