breaking a big file into smaller files

harish13's Avatar
Go4Expert Member
i want to break a large file into smaller files each of size 2KB.i want to give the file names as 1.txt,2.txt,3.txt etc how can i do this
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Use the following code
Code: VB
Dim sBucket As String
Dim LenFile1 As Long
Dim i As Integer

Open "c:\file.bin" For Binary As #1
LenFile1 = LOF(1)

i = 1

Do While Not EOF(1)
    Select Case (LOF(1) - Loc(1))
        Case Is >= 2048
            Dim filename As String
            filename = "C:\temp" + i + ".bin"
            i = i + 1
            sBucket = String(2048, " ") 'Copy 2K at a time.
            Open filename For Binary As #2
        Case 0
            Exit Do 'end of file
        Case Else
            sBucket = String(LOF(1) - Loc(1), " ") 'Amount left is smaller then 2K so grab it
    End Select

    Get 1, , sBucket  'get data from file 1
    Put 2, , sBucket  'put data to file 2
Loop

Close #1
Close #2
0
harish13's Avatar
Go4Expert Member
thank u for the reply
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
My pleasure.