breaking a big file into smaller files

Discussion in 'Visual Basic ( VB )' started by harish13, Jul 24, 2006.

  1. harish13

    harish13 New Member

    Joined:
    Jul 20, 2006
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    0
    :confused: 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
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Use the following code
    Code:
    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
    
     
  3. harish13

    harish13 New Member

    Joined:
    Jul 20, 2006
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    0
    thank u for the reply
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    My pleasure.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice