Logo
English Russian German French Spanish Italian
contact usprivacy
   Support Forums
chart
• Adjust flexgrid cell
• Animation
• Centering form text
• Coffee machine
• Creating fileshares
• Creating shortcuts
• Custom buttons
• Directory browser
• Disable mouse events
• File search by ext
• File transfer
• File watcher
• Formatting flexgrid
• Get Content Type
• Get HTML source
• Get modem port
• HTTP proxy
• ipconfig
• Large file split/merge
• MAPI
• MCI Sound Player
• Menu with images
• MP3 normalizer
• Net Send
• Netstat 2000
• No duplicate entries
• Outlook Address Book
• Set font color
• Shapes
• SOAP test
• Text-to-image
• Text file viewer
• Text find/replace
• UPS component
• View NT groups
• Word template
• Writing DNS control
    • Using DNS control
• Writing SMTP control
    • Sending email
    • Mailing list
• Writing WhoIs control
    • Using WhoIs control
• View HTML source
OISV - Organization of Independent Software Vendors - Contributing Member
VB projects - Large File Split/Merge

Description: Splitting large file onto smaller ones and merging it back
Minimum requirements: vb
Download: source code
Screenshot:
file split
Project: Standard EXE
Controls: txtFile (Textbox), txtSize (Textbox), txt (Textbox, MultiLine set to True), cmb (ComboBox), lblOut (Label), cmdBrowse (Command button), cmdSplit (Command button), cmdMerge (Command button), dlg (CommonDialog Control)
Code:
Dim nLen As Double
Dim strFName As String
Dim b() As Byte

Private Sub cmdBrowse_Click()
    dlg.ShowOpen
    txtFile = dlg.FileName
    strFName = dlg.FileTitle
End Sub

Private Sub cmdMerge_Click() ' merge previously splitted file to its split direcory
    Dim n As Double: Dim i As Long: Dim bOpen As Boolean: Dim d As Double

    For i = 0 To File1.ListCount - 1
        If IsNumeric(Right(File1.List(i), 3)) Then
            If Not bOpen Then
                Open lblOut & "\" & Left(File1.List(i), Len(File1.List(i)) - 4) For Binary As 2
                bOpen = True
            End If
            n = FileLen(lblOut & "\" & File1.List(i))
            Open lblOut & "\" & File1.List(i) For Binary As 1
            ReDim b(n - 1)
            Get #1, , b()
            Put #2, d + 1, b()
            Close #1
            d = d + n
        End If
    Next
    Close #2
    File1.Refresh
End Sub

Private Sub cmdSplit_Click() 'split file on two equal files
    If Trim(txtFile) = "" Or Dir(txtFile) = "" Then
        MsgBox "File doesn't exist"
        cmdBrowse.SetFocus
        Exit Sub
    End If
    If Val(txtSize) < 1 Then
        MsgBox "Incorrect split size"
        txtSize.SetFocus
        Exit Sub
    End If
    On Error GoTo er1
    lblOut = txtFile & "_split"
    lblOut.Refresh
    MkDir lblOut
    File1.Path = lblOut
    File1.Visible = True
    txt.Visible = False
    If cmb.ListIndex = -1 Then cmb.ListIndex = 2
    Dim i As Long 'number of file
    Dim ss As Double 'split size
    If cmb.ListIndex = 0 Then
        ss = 1024
        ss = ss * 1024
    ElseIf cmb.ListIndex = 1 Then
        ss = 1024
    Else
        ss = 1
    End If
    ss = Round(Val(txtSize) * ss, 0)
    nLen = FileLen(txtFile)
    Open txtFile For Binary As 1
    While nLen > ss
        ReDim b(ss - 1)
        Get #1, ss * i + 1, b()
        Open lblOut & "\" & strFName & "." & Format(i, "000") For Binary As 2
        Put #2, , b()
        Close #2
        File1.Refresh
        i = i + 1
        nLen = nLen - ss
    Wend
    ReDim b(nLen - 1)
    Get #1, ss * i + 1, b()
    Open lblOut & "\" & strFName & "." & Format(i, "000") For Binary As 2
    Put #2, , b()
    Close #2
    File1.Refresh
    Beep
    Close #1
    Exit Sub
er1:
    Select Case Err
    Case 75
        If MsgBox("Split folder already exist. Would you like to overwrite it?", vbYesNo) = vbYes Then
            Dim j As Long
            File1.Path = lblOut
            For j = File1.ListCount - 1 To 0 Step -1
                Kill lblOut & "\" & File1.List(j)
            Next
            RmDir lblOut
            Resume
        Else
            lblOut = "Output Directory"
        End If
    Case Else
        MsgBox Err.Number & ": " & Err.Description
    End Select
End Sub

Private Sub Form_Load()
    cmb.ListIndex = 0
    File1.Visible = False
End Sub

Copyright © 1996-2012 OstroSoft. All rights reserved. info@ostrosoft.com