用VB6.0实现将多个TXT文件合并成一个TXT文件

2024-11-25 10:09:11
推荐回答(1个)
回答1:

Private Sub CommandButton1_Click()
Dim fRead, fWrite
Dim i%
Dim Buf() As Byte
Dim ReadFile(10) As String
Dim sPath As String
Dim sName As String
sPath = "D:\"
ReadFile(0) = "01.Txt": ReadFile(1) = "02.txt": ReadFile(2) = "03.txt"
fWrite = FreeFile
Open "D:\合并.txt" For Binary As fWrite
For i = 0 To 2
fRead = FreeFile
sName = sPath + ReadFile(i)
Open sName For Binary As fRead
ReDim Buf(FileLen(sName) + 1)

Get fRead, , Buf
Buf(UBound(Buf)) = 10
Buf(UBound(Buf) - 1) = 13
Put fWrite, , Buf
Close (fRead)

Next
Close (fWrite)

End Sub