Transfer text file content
Hi everyone, can someone show me a code how to transfer content of a text file to another text file?
one text file named A.text i want to open using "For Open" and another one (B.text) using "For Append"..so i want everything in A.text transfer to B.text
Re: Transfer text file content
Try this code, add reference for Microsoft Scripting Runtime library in Project>References
VB Code:
Dim strTemp$
Dim objFSO as Scripting.FileSystemObject, objSourceFile as Scripting.TextStream,objOutputFile as Scripting.TextStream
Set objFSO=New Scripting.FileSystemObject
Set objSourceFile=objFSO.OpenTextFile("source.txt")
Set objOutputFile=objFSO.OpenTextFile("output.txt",ForAppending)
Do While Not objSourceFile.AtEndOfStream
strTemp=objSourceFile.ReadLine
objOutputFile.WriteLine strTemp
Loop
objOutputFile.Close
objSourceFile.Close
Set objOutputFile=Nothing
Set objSourceFile=Nothing
Set objFSO=Nothing
Re: Transfer text file content
Re: Transfer text file content
VB Code:
Dim FSO As FileSystemObject
Set FSO = New FileSystemObject
FSO.CopyFile "sourceFile", "destinationFile", True 'True for overwrite
Re: Transfer text file content
this is how to do it if you don't want to use the file system object (FSO)
more or less what you had in your post
VB Code:
Open "a.txt" For Input As 1
atxt = Input(LOF(1), #1)
Close 1
Open "b.txt" For Append As 1
Print #1, atxt
Close 1
Re: Transfer text file content
Why not just FileCopy if all you want to do is copy the contents from one file to another.
Re: Transfer text file content
from his original post it would appear he wanted to add the content to the second existing file