• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 139
  • Last Modified:

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
0
no1nincompoop
Asked:
no1nincompoop
1 Solution
 
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now