VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code will cut files in 2 pieces at specified length or file split a large file into multiple o

by John Maskeny (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 26th July 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This code will cut files in 2 pieces at specified length or file split a large file into multiple ones.

Rate This code will cut files in 2 pieces at specified length or file split a large file into multiple o



'#Code Made by:        #
'#John Maskeny         #
'#07/26/00             #
'#[email protected]#

Public Function SplitFile(ByVal StartFile As String, SplitSize As Long, MultiFile As Boolean)
    Dim OpenFile As Integer, FileSplit As String, LenFile As Long, SplitPos As Long, Openfile2 As Integer, i As Integer, count As Integer

    SplitPos = 1 ' Starting position
    If StartFile <> "" Then ' Error checking
        
        OpenFile = FreeFile
        Open StartFile For Binary Access Read As OpenFile 'Open sourcefile
        LenFile = LOF(OpenFile) 'File length
        count = 0 ' reset count
        Do Until SplitPos >= (LenFile) 'do to end of file
            count = count + 1 'add 1 to count
            Openfile2 = FreeFile
            
            Open StartFile & count For Binary As Openfile2 'open destination file
            
            If count > 1 And MultiFile = False Then 'if not multi file then we just want to cut it
                FileSplit = Space$(LenFile - SplitSize)
            Else
                FileSplit = Space$(SplitSize) 'else make and many sets as sized
            End If
            
            Get #OpenFile, SplitPos, FileSplit ' Get chunk
            
            If SplitPos + SplitSize > LenFile Then ' if at end of file get the rest
               Put #Openfile2, , Mid$(FileSplit, 1, (LenFile - SplitPos))
            Else
                Put #Openfile2, , FileSplit
            End If
            
            If count > 1 And MultiFile = False Then ' if not multi file we only want 2 parts
                SplitPos = LenFile
            Else
                SplitPos = SplitPos + SplitSize
            End If
            
            Close #Openfile2 'close file
         Loop
         Close #OpenFile
  End If
    
End Function

Download this snippet    Add to My Saved Code

This code will cut files in 2 pieces at specified length or file split a large file into multiple o Comments

No comments have been posted about This code will cut files in 2 pieces at specified length or file split a large file into multiple o. Why not be the first to post a comment about This code will cut files in 2 pieces at specified length or file split a large file into multiple o.

Post your comment

Subject:
Message:
0/1000 characters