Click here to Skip to main content
Click here to Skip to main content

File Split & Merge Tool

, 9 Aug 2002
Rate this:
Please Sign up or sign in to vote.
This tool is used to split large files into smaller chunks and merge them back into a single file.

Sample Image - File_Split___Merge_Tool.jpg

Summary

This tool is used to split large files into smaller chunks of your choice and merge them back into single file. This is extremely useful when copying files into floppies or while transferring files over network.

Introduction

This project consists of a class SplitMerge.vb and a user interface to test the class. Source code is provided as a VS.NET project, so you can download the source and build it with current version of VS.NET. I created and tested this under VS.NET with SP2 under Windows 2000.

This project demonstrates the usage of file streams, threading and events in VB.NET.

Description

SplitMerge.VB

This class has two primary methods SplitFile and MergeFile.

  • SplitFile

    Splits files into smaller chunk files.

    • FileName: File name to split with full path
    • OutputPath: Output folder name where the chunk files will be created. Chunk files will be created with the same name as input file with suffix of sequence number (e.g.: bigfile.exe.001)
    • DeleteFileAfterSplit: Boolean value indicating, whether to delete the input file after splitting.
    • ChunkSize: Long value indicating the chunk size in bytes.
  • MergeFile

    Merges all the chunk files into one file.

    • FileName: First chunk file name with full path or the file name with full path (In this case c:\bigfile.exe.001 or c:\bigfile.exe)
    • OutputPath: Output folder name where the merged file will be created
    • DeleteFilesAfterMerge: Boolean value indicating, whether to delete the chunk file after merge.

Both these methods are thread safe and can be called as background threads

Events

This class has 3 events.

  • FileSplitCompleted  - This event is raised after the split process is completed
  • FileMergeCompleted - This event is raised after the merge process is completed
  • UpdateProgress - This event is raised to notify the client about the progress. Raised after each chunk file is created.

Using SplitMerge class

Add a form to your project. Declare SplitMerge class with events.

Private WithEvents _FileSplitMerge As New SplitMerge() 

Declare a thread to call the Split and Merge Methods

Private backgroundThread As System.Threading.Thread

See the demo for other controls 

Calling Split process

Private Sub SplitFile()
    With _FileSplitMerge.ChunkSize = txtChunkSize.Text
        .FileName = txtFileName.Text
        .OutputPath = txtOutputFolder.Text
        .DeleteFileAfterSplit = chkOption.Checked
        backgroundThread = New _ 
         Threading.Thread(AddressOf .SplitFile)backgroundThread.Start()
    End With
End Sub

After the split process is completed, it will raise the FileSplitCompleted event.

FileSplitCompleted event will return an ErrorMessage, in case of an error it will return the error message else an empty string.

Private Sub _FileSplitMerge_FileSplitCompleted(ByVal _ 
          ErrorMessage As String) Handles _FileSplitMerge.FileSplitCompleted
    If ErrorMessage = "" Then
        MsgBox("File Split process completed")
    Else
        MsgBox("File Split process Failed" & NEWLINE & ErrorMessage)
    End If
    ResetControls()
End Sub

So check for the ErrorMessage to display appropriate message.

Calling Merge procedure

Private Sub MergeFiles()
    With _FileSplitMerge.FileName = txtFileName.Text
        .OutputPath = txtOutputFolder.Text
        .DeleteFilesAfterMerge = chkOption.Checked
        backgroundThread = New _ 
          Threading.Thread(AddressOf .MergeFile)backgroundThread.Start()
    End With
End Sub

Events are the same as Split process.

Demo comes with a fully functional example.

Notes & ToDo features

I would like to enhance this further by adding Crypt, Compression and password functionalities in next version.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Sreenivas Vemulapalli
Web Developer
United States United States
Working as consultant in Client/server,Web Development, Automation areas using C#,Vb,Vb.net,Asp.net,Sql Server,Xml,Html&Dhtml etc..
Looking for a challenging project in .NET

Comments and Discussions

 
QuestionProblem with large files PinmemberMuthuraj81422-Dec-11 21:39 
QuestionSpliting files with different extensions in vb.net PinmemberPavi345612-Jul-11 4:42 
GeneralGreat! PinmemberJesse Garcia28-Jul-08 21:43 
GeneralI want to know.... [modified] Pinmembertj_istar9-Aug-07 3:42 
GeneralCommercial Split/Merge Pinmemberwinnovative27-Jun-07 19:14 
GeneralRe: Commercial Split/Merge PinmemberThe JZ23-Feb-08 8:53 
QuestionHow do i send the split files over LAN? Pinsussred_kops30-Aug-05 8:56 
GeneralDoesn't work for large files Pinmemberluke73489728924-Aug-05 10:09 
GeneralRe: Doesn't work for large files Pinmemberluke73489728924-Aug-05 10:26 
Generalslow but good PinmemberAhmed ceder25-Sep-04 12:17 
GeneralRe: slow but good PinmembereRRaTuM30-Mar-06 5:21 
GeneralPDF File Merge PinmemberZulfikar Ali4-Oct-02 10:37 
GeneralRe: PDF File Merge PinmemberSreenivas Vemulapalli4-Oct-02 12:26 
Generaltry this PinmemberSreenivas Vemulapalli4-Oct-02 12:29 
GeneralRe: try this PinmemberZulfikar Ali4-Oct-02 12:50 
GeneralSpeed enhancement PinmemberPaul A. Howes12-Aug-02 3:47 
GeneralRe: Speed enhancement PinmemberSreenivas Vemulapalli12-Aug-02 13:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141216.1 | Last Updated 10 Aug 2002
Article Copyright 2002 by Sreenivas Vemulapalli
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid