Quick Search for:  in language:    
code,will,read,large,file,split,into,smaller,
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Visual Basic Stats

 Code: 3,011,557. lines
 Jobs: 115. postings

 How to support the site

 
Sponsored by:

 

You are in:

 
Login



Latest Code Ticker for Visual Basic.
AniViewer
By Jerrame Hertz on 6/30


Click here to see a screenshot of this code!Raw Packet Sniffer
By Coding Genius on 6/30

(Screen Shot)

Check the support of a record set
By Freebug on 6/30


B++ Builder - VB without runtimes
By Anthonius on 6/30


Mr Blonde - Chat Program
By Mr Blonde on 6/30


MSN Messenger Status Detector
By Ryan Cain on 6/30


MSN advanced
By alias1990 on 6/30


MSN Messenger advanced
By alias1990 on 6/30


Locate Database
By Erica Ziegler-Roberts on 6/30


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

Split any file into smaller files

Print
Email
 

Submitted on: 4/26/1999
By: Riaan Aspeling  
Level: Not Given
User Rating: By 101 Users
Compatibility:VB 5.0, VB 6.0

Users have accessed this code 9276 times.
 
 
     This code will read any large file and split it into smaller chuncks so you can copy to stiffy,e-mail or ftp it. This code is for you out there playing with file management etc. This code is very basic but it does some cool things. It will leave the source file and will create a bunch of smaller files in the same directory.. This code can be modified to output directly to the stiffy drive if you want.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

'**************************************
' Name: Split any file into smaller file
'     s
' Description:This code will read any la
'     rge file and split it into smaller chunc
'     ks so you can copy to stiffy,e-mail or f
'     tp it. This code is for you out there pl
'     aying with file management etc. This cod
'     e is very basic but it does some cool th
'     ings. It will leave the source file and 
'     will create a bunch of smaller files in 
'     the same directory.. This code can be mo
'     dified to output directly to the stiffy 
'     drive if you want.
' By: Riaan Aspeling
'
' Inputs:Create a new form and drop four
'     Command Buttons on it (Command1 to Comma
'     nd4). Also drop a Textbox on it (Text1) 
'     and a Combobox (Combo1). You can (if you
'     want) place a label above the textbox an
'     d change it's caption to "Source File" a
'     nd a label above the combobox and change
'     it's caption to "Split File size".
Now copy the source into the form and the module. Run and have fun ;).
If you make a nice util With the code please send me a copy : riaana@hotmail.com
'
' Returns:Split files with extensions fr
'     om Myfile.000 to MyFile.999
'
' Assumes:If checked the split files aft
'     er I've Assembled them again with FC (Fi
'     leCompare) in binary mode and it didn't 
'     find any differences. But you should kno
'     w that you are playing with files so don
'     't delete the origanal after you've chec
'     ked that you can re-assemble it ok.
'
' Side Effects:None that I know of... Th
'     is code can be a basis for a cool util (
'     You have to e-mail me that cool util .. 
'     riaana@hotmail.com)
'
'This code is copyrighted and has' limited warranties.Please see http://w
'     ww.Planet-Source-Code.com/vb/scripts/Sho
'     wCode.asp?txtCodeId=1662&lngWId;=1'for details.'**************************************

'***********************************
'*** PASTE THIS CODE INTO A FORM ***
'***********************************
Option Explicit
Private Sub Command1_Click()

Dim Ans As String Ans = GetOpenFileNameDLG("File to split *.*|*.*|File to combine *.000|*.000|", "Please Select a file", "", Me.hwnd) If Ans <> "" Then Text1.Text = Ans End If
End Sub
Private Sub Command2_Click()
'Check that somting is selected If Not CheckForFile Then Exit Sub 'Ok split the file in the current direct ' ory If SplitFile(Text1.Text, Combo1.ItemData(Combo1.ListIndex)) Then MsgBox "File was split!" Else MsgBox "Error splitting file..." End If
End Sub
Private Sub Command3_Click()
'Check that somting is selected If Not CheckForFile Then Exit Sub 'Check to see if it is a Split file with ' extension "MYFILE.SP(x)" If (Right$(Text1.Text, 3)) <> "000" Then MsgBox "That's Not the proper extension For a split file. It should be somthing like Myfile.000, the first file of the split files.", 16, "No go !" Exit Sub End If
'Ok assemble the files in the current di ' rectory If AssembleFile(Text1.Text) Then MsgBox "File assembled!" Else MsgBox "Error assembeling file..." End If
End Sub
Private Sub Command4_Click()
Unload Me End End Sub
Private Sub Form_Load()
Text1.Text = "" Combo1.AddItem "16 Kb" Combo1.ItemData(Combo1.NewIndex) = 16 Combo1.AddItem "32 Kb" Combo1.ItemData(Combo1.NewIndex) = 32 Combo1.AddItem "64 Kb" Combo1.ItemData(Combo1.NewIndex) = 64 Combo1.AddItem "128 Kb" Combo1.ItemData(Combo1.NewIndex) = 128 Combo1.AddItem "256 Kb" Combo1.ItemData(Combo1.NewIndex) = 256 Combo1.AddItem "512 Kb" Combo1.ItemData(Combo1.NewIndex) = 512 Combo1.AddItem "720 Kb" Combo1.ItemData(Combo1.NewIndex) = 720 Combo1.AddItem "1200 Kb" Combo1.ItemData(Combo1.NewIndex) = 1200 Combo1.AddItem "1440 Kb" Combo1.ItemData(Combo1.NewIndex) = 1440 Combo1.ListIndex = Combo1.ListCount - 1 Command1.Caption = "Browse" Command2.Caption = "Split File" Command3.Caption = "Assemble Files" Command4.Caption = "Cancel" End Sub
Function CheckForFile() As Boolean
'We don't want nasty spaces in the end Text1.Text = Trim(Text1.Text) CheckForFile = False 'Check for text in textbox If Text1.Text = "" Then 'Stop !! no text entered MsgBox "Please Select a file first!", 16, "No file selected" Exit Function End If
'Check if the file excists If Dir$(Text1.Text, vbNormal) = "" Then 'Stop !! no file MsgBox "The file '" & Text1.Text & "' was Not found!", 16, "File non excistend?!" Exit Function End If
CheckForFile = True End Function
Function SplitFile(Filename As String, Filesize As Long) As Boolean
On Error Goto handelsplit Dim lSizeOfFile As Long, iCountFiles As Integer Dim iNumberOfFiles As Integer, lSizeOfCurrentFile As Long Dim sBuffer As String '10Kb buffer Dim sRemainBuffer As String, lEndPart As Long Dim lSizeToSplit As Long, sHeader As String * 16 Dim iFileCounter As Integer, sNewFilename As String Dim lWhereInFileCounter As Long If MsgBox("Continue To split file?", 4 + 32 + 256, "Split?") = vbNo Then SplitFile = False Exit Function End If
Open Filename For Binary As #1 lSizeOfFile = LOF(1) lSizeToSplit = Filesize * 1024 'Check if the file is actualy larger tha ' n the selected split size If lSizeOfFile <= lSizeToSplit Then Close #1 SplitFile = False MsgBox "This file is smaller than the selected split size! Why split it ?", 16, "Duh!" Exit Function End If
'Check if file isn't alread split sHeader = Input(16, #1) Close #1 If Mid$(sHeader, 1, 7) = "SPLITIT" Then MsgBox "This file is alread split!" SplitFile = False Exit Function End If
Open Filename For Binary As #1 lSizeOfFile = LOF(1) lSizeToSplit = Filesize * 1024 'Write the header of the split file ' Signature = "SPLITIT" = Size 7 ' Split Number= "xxx" = Size 3 ' Total Number of Split Files = "xxx" = ' Size 3 ' Origanal file extension = "aaa" = Size ' 3 'Total of 16 for header iCountFiles = 0 iNumberOfFiles = (lSizeOfFile \ lSizeToSplit) + 1 sHeader = "SPLITIT" & Format$(iFileCounter, "000") & Format$(iNumberOfFiles, "000") & Right$(Filename, 3) sNewFilename = Left$(Filename, Len(Filename) - 3) & Format$(iFileCounter, "000") Open sNewFilename For Binary As #2 Put #2, , sHeader 'Write the header lSizeOfCurrentFile = Len(sHeader) While Not EOF(1) Me.Caption = "File Split : " & iFileCounter & " (" & Int(lSizeOfCurrentFile / 1024) & " Kb)" Me.Refresh sBuffer = Input(10240, #1) lSizeOfCurrentFile = lSizeOfCurrentFile + Len(sBuffer) If lSizeOfCurrentFile > lSizeToSplit Then 'Write last bit lEndPart = Len(sBuffer) - (lSizeOfCurrentFile - lSizeToSplit) + Len(sHeader) Put #2, , Mid$(sBuffer, 1, lEndPart) Close #2 'Make new file iFileCounter = iFileCounter + 1 sHeader = "SPLITIT" & Format$(iFileCounter, "000") & Format$(iNumberOfFiles, "000") & Right$(Filename, 3) sNewFilename = Left$(Filename, Len(Filename) - 3) & Format$(iFileCounter, "000") Open sNewFilename For Binary As #2 Put #2, , sHeader 'Write the header 'Put Rest of buffer read Put #2, , Mid$(sBuffer, lEndPart + 1) lSizeOfCurrentFile = Len(sHeader) + (Len(sBuffer) - lEndPart) Else Put #2, , sBuffer End If
Wend
Me.Caption = "Finished" Close #2 Close #1 SplitFile = True Exit Function handelsplit: SplitFile = False MsgBox Err.Description, 16, "Error #" & Err.Number Exit Function End Function
Function AssembleFile(Filename As String) As Boolean
On Error Goto handelassemble Dim sHeader As String * 16 Dim sBuffer As String '10Kb buffer Dim sFileExt As String, iNumberOfFiles As Integer Dim iCurrentFileNumber As Integer Dim iCounter As Integer, sTempFilename As String Dim sNewFilename As String If MsgBox("Continue To assemble file?", 4 + 256 + 32, "Assemble?") = vbNo Then AssembleFile = False Exit Function End If
Open Filename For Binary As #1 sHeader = Input(Len(sHeader), #1) 'Check if it's a split file !!! If Mid$(sHeader, 1, 7) <> "SPLITIT" Then MsgBox "This is Not a split file ;) nice try!" AssembleFile = False Exit Function Else 'The first file is a split file ok 'Read the header values iCurrentFileNumber = Val(Mid$(sHeader, 8, 3)) iNumberOfFiles = Val(Mid$(sHeader, 11, 3)) sFileExt = Mid$(sHeader, 14, 3) If iCurrentFileNumber <> 0 Then MsgBox "This is Not the first file In the sequence!!! AAAGGHH!" AssembleFile = False Exit Function End If
End If
Close #1 sNewFilename = Left$(Filename, Len(Filename) - 3) & sFileExt 'Create the assembled file Open sNewFilename For Binary As #2 'Assemble files For iCounter = 0 To iNumberOfFiles - 1 sTempFilename = Left$(Filename, Len(Filename) - 3) & Format$(iCounter, "000") Me.Caption = "File Assemble : " & sTempFilename Me.Refresh Open sTempFilename For Binary As #1 sHeader = Input(Len(sHeader), #1) If Mid$(sHeader, 1, 7) <> "SPLITIT" Then MsgBox "This is Not a split file ;) nice try! " & sTempFilename AssembleFile = False Exit Function End If
iCurrentFileNumber = Val(Mid$(sHeader, 8, 3)) If iCurrentFileNumber <> iCounter Then MsgBox "The file '" & sTempFilename & "' is out of sequence!! AARRGHH!" AssembleFile = False Close #2 Close #1 Exit Function End If
While Not EOF(1) sBuffer = Input(10240, #1) Put #2, , sBuffer Wend
Close #1 Next iCounter
Close #2 Me.Caption = "Finished" AssembleFile = True Exit Function handelassemble: AssembleFile = False MsgBox Err.Description, 16, "Error #" & Err.Number Exit Function End Function


Other 24 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
5/12/1999 3:19:00 AM:Dan Messenger
I tried this program and it seemed to 
work fine. I told it to split an 5mb 
file into 720k files. It was working 
away and creating the files fine untill 
it got into the 8th file. At this point 
an error message occured saying 'Input 
past end of file'.
Any 
solutions?
Thanks in advance
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/13/1999 1:30:00 AM:Riaan Aspeling
Hi Dan
The Form_Load event had a 
type-o with one of the ItemData fields. 
It 
read:
Combo1.ItemData(Combo1.NewIndex
) = 702
I've changed it 
to
Combo1.ItemData(Combo1.NewIndex) 
= 720
I hope that fixes it ;)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/15/1999 7:42:00 AM:Adam
It is nice code, and it is work fine, I 
did some changes in it, I add 
progressbar,
GREAT JOB..
Thanks for 
Riaan Aspeling.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/15/1999 7:46:00 AM:Adam
It is nice code, and it is work fine, I 
did some changes in it, I added 
progressbar,
GREAT JOB..
Thanks for 
Riaan Aspeling.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/15/1999 2:25:00 PM:Daniel
Adam, can you please mail me your 
source code with the 
progressbar?
Thanks
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/27/1999 10:19:00 AM:Afdah Wahid
Cool proggy. Keep up the good work!
By 
the way any of you guys know how to 
make it works faster?
Because it takes 
ages to split a 20MB file.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/29/1999 10:12:00 AM:Bill
good program I got it to work great and 
i changed it around a little but I have 
two problems -> one, when you split a 
file on the desktop and then try to 
assemble it it causes and error, why is 
this? two, how would i change it so the 
user can change the destination file of 
the split up files? If someone could 
please help me with these problems that 
would be great
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/29/1999 12:47:00 PM:Justin Uy
Great concept. I'm having a constant 
problem though. Every time the splitter 
gets to the last file to split it says 
"Input past end of file" "Error #62" Is 
there a way to take care of this? 
Thanks.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/29/1999 12:53:00 PM:Justin Uy
Oh yeah. When I removed the error 
handling code this is the text it 
wanted me to debug.
sBuffer = 
Input(10240, #1)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/30/1999 6:35:00 AM:Riaan Aspeling
Hi Justin.
Are you using VB5 Service 
Pack 3. I've had another coder ask me 
the same question , he was using VB4.. 
I believe VB5 handels the eof senario 
by just dumping the last bit of data 
into the sBuffer string. eg. :
The 
file is 18kb... It will read the first 
10kb ok .. second time round the 
sbuffer will be 8kb. (with vb4 it will 
give you and error : Past End Of File, 
or something... this can be modified by 
checking the size of the remaining file 
constantly.. eg:
Make a variable with 
the initial size of the file x = 
lof(FileNumber) decrement the x 
variable by 10240 (10kb) for every 
read, then check the x variable before 
you read from the file to see if it is 
smaller than 10kb (10240) and adjust 
the read like :
    sBuffer = 
input(x,FileNumber)
Where x will be 
smaller then 10240 and only read the 
phisical amount of bytes left in the 
file.
Kind Regards
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/30/1999 6:43:00 AM:Riaan Aspeling
Hi Afdah.
Thanks for the compliment 
!
To speed this program up I believe 
you can just make the read buffer 
bigger. (Don't exceed 64Kb though.. it 
will crash your system or give totally 
unpredictable results.
Check where 
you find 10240... this is the buffer 
size 10kb. Change this to .... let's 
say 20480 (20kb) this should make a 
speed difference...
Keep 
Coding
Kind Regards
Riaan Aspeling
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/30/1999 5:56:00 PM:Erik
How do you have it split the files up 
with the extensions for exaple: .nfs?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/31/1999 12:01:00 PM:Justin DuJardin
thats some nice code there riaan it 
seems to work fine for me but i removed 
the 10k read buffer and did a 32k read 
buffer to speed it up and i also added 
a progress bar and some other small 
changes but other than that it is great 
code it inspired me to create the 
opposite so i am creating a file packer 
it takes many file kinda like winzip 
and packs them into one file but they 
arent compressed so its kinda pointless 
but its a challenge to do it without 
messing up any file headers especially 
on graphic files.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
6/10/1999 8:01:00 AM:Aniruddha Ray
Hi Justin:
Is it possible to get a 
copy of the code with the progress bar? 
If so, could you pl. e-mail me 
one?
Thanks.
Ray.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/15/1999 8:11:00 AM:DMess
Hi, i have been lookin through this 
code and presume that what it does is 
open the file in binary mode or 
something and then puts it into loads 
of little files. Does anybody know how 
to put this info into a text file or 
something so that an other program can 
read it a reconstruct the file??
Any 
help would be appriecited
DMess
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/12/1999 5:58:00 PM:Alexandre Gosselin
Can anyone tell me how to add a 
progress bar to this program?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/19/1999 4:28:00 PM:Anonymous
This code is garbage.  It would take 
minutes to split a 10 megabyte file!  
What's wrong with using the windows 
APIs to do it the right way?  I'm glad 
you've taken up VB as a hobby... But 
let's try to put some more thought into 
these submissions.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/27/1999 2:51:00 PM:Jake
hey riaan man this code works great at 
dsaccembling but i cant get it to 
reassemble. Could you or someone else 
gimmie some help?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/30/1999 12:36:00 PM:Paul Mather
Yes, download my code "Large File 
Splitter"
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/6/1999 2:46:00 PM:Woooooooodard
Ne1 got the code to recombine the files 
after they are split? Like in order to 
split an exe, and send it through 
multiple connections, and then 
recombine it.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/29/1999 2:33:00 PM:Paul Mather
Here's an efficient way of splitting 
files: 
http://www.planet-source-code.com/vb/scr
ipts/ShowCode.asp?txtCodeId=3582
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
11/30/1999 5:42:00 AM:Andrew Timberlake
This program is really usefull for 
getting roms to abd from college on 
disk since most are more than 1 
meg
Thanks
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Visual Basic Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.