Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   breaking a big file into smaller files (http://www.go4expert.com/forums/breaking-file-smaller-files-t1055/)

harish13 24Jul2006 09:47

breaking a big file into smaller files
 
:confused: i want to break a large file into smaller files each of size 2KB.i want to give the file names as 1.txt,2.txt,3.txt etc how can i do this

shabbir 24Jul2006 23:05

Re: breaking a big file into smaller files
 
Use the following code
Code: VB

Dim sBucket As String
Dim LenFile1 As Long
Dim i As Integer

Open "c:\file.bin" For Binary As #1
LenFile1 = LOF(1)

i = 1

Do While Not EOF(1)
    Select Case (LOF(1) - Loc(1))
        Case Is >= 2048
            Dim filename As String
            filename = "C:\temp" + i + ".bin"
            i = i + 1
            sBucket = String(2048, " ") 'Copy 2K at a time.
            Open filename For Binary As #2
        Case 0
            Exit Do 'end of file
        Case Else
            sBucket = String(LOF(1) - Loc(1), " ") 'Amount left is smaller then 2K so grab it
    End Select

    Get 1, , sBucket  'get data from file 1
    Put 2, , sBucket  'put data to file 2
Loop

Close #1
Close #2


harish13 25Jul2006 09:01

Re: breaking a big file into smaller files
 
thank u for the reply

shabbir 25Jul2006 10:21

Re: breaking a big file into smaller files
 
My pleasure.


All times are GMT +5.5. The time now is 20:23.