Splitting a file....

hi.. all

Can anyone tell me how to split a file....... and join it....
Can anyone give me some sample code for tht...

regards
no1nincompoop
no1nincompoopAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gwosgoodIT MgrCommented:
what do you mean splitting a file?
do you want to parse the filename?
or do you want to take a certain section of a file's contents and merge it with another?
0
kurian2z5Commented:
You need two command buttons cmdSplit and cmdJoin and a textbox txtPath

When u click split it reads the txtpath and splits the file into parts each of size as specified in partsize. the parts are named filename.1 filename.2 etc. and saved in c:\ in this case.

When u click join you have the specify the original name of the file, eg filename.exe (without the folder path) and the number of parts that it has been split into. the parts are read from c:\ in this case and they are joined to form the original file.

Private Sub cmdJoin_Click()
Dim i As Integer
Dim Parts As Integer
Dim FName As String
Dim Buffer As String
Dim Pos As Long

Pos = 1

FName = InputBox("Enter original name of file")
Parts = CInt(InputBox("Enter no of source parts"))

Open "c:\" & FName For Binary Access Write As #1

For i = 1 To Parts
    Open "c:\" & FName & "." & i For Binary Access Read As #2
   
    Buffer = Space$(LOF(2))
    Get #2, , Buffer
    Put #1, Pos, Buffer
   
    Pos = Pos + LOF(2)
   
    Close #2
   
    Kill "c:\" & FName & "." & i
   
Next i

Close #1

End Sub

Private Sub cmdSplit_Click()

Dim i As Long
Dim c As Integer
Dim FLen As Long
Dim Rep As Long
Dim Remain As Long
Dim FName As String 'name of the file
Dim PartSize As Long
Dim Buffer As String 'temporary buffer

PartSize = 1000 ' size of each portion of the split file
FLen = FileLen(txtPath.Text) 'size of the file in bytes
Rep = Int(FLen / PartSize) ' no of portions the file is split into
Remain = FLen Mod PartSize ' last few bytes remaining not divisible by 1000
FName = Right(txtPath.Text, Len(txtPath.Text) - InStrRev(txtPath.Text, "\"))
Debug.Print FName

c = 1
i = 1
Open txtPath.Text For Binary Access Read As #1

While c <= Rep
    Buffer = Space$(PartSize)
    Get #1, i, Buffer ' read part of the source file into the temporary buffer

    Open "c:\" & FName & "." & CStr(c) For Binary Access Write As #2
        Put #2, , Buffer
    Close #2
    c = c + 1
    i = i + PartSize
Wend


If Remain > 0 Then
    Buffer = Space$(Remain)
    Get #1, i, Buffer
   
    Open "c:\" & FName & "." & CStr(c) For Binary Access Write As #2
        Put #2, , Buffer
    Close #2

End If

Close #1

End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.