VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Split any file into smaller files

Riaan Aspeling  (14 Submissions)   Complete Applications   Visual Basic 3.0   Unknown Difficulty   Wed 3rd February 2021

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.

Inputs
Create a new form and drop four Command Buttons on it (Command1 to Command4). Also drop a Textbox on it (Text1) and a Combobox (Combo1). You can (if you want) place a label above the textbox and change it's caption to "Source File" and 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 : [email protected]

Assumes
If checked the split files after I've Assembled them again with FC (FileCompare) in binary mode and it didn't find any differences. But you should know that you are playing with files so don't delete the origanal after you've checked that you can re-assemble it ok.

Returns
Split files with extensions from Myfile.000 to MyFile.999

Side Effects
None that I know of... This code can be a basis for a cool util (You have to e-mail me that cool util .. [email protected])

API Declarations
'*************************************
'*** PASTE THIS CODE INTO A MODULE ***
'*************************************
Option Explicit
Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
Public Type SHITEMID
mkidcb As Long
abID As Byte
End Type
Public Type ITEMIDLIST
idlmkid As SHITEMID
End Type
Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Public Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Public Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Public Const BIF_RETURNONLYFSDIRS = &H1
Function GetOpenFileNameDLG(Filter As String, Title As String, DefaultExt As String, WindowHnd As Long) As String
On Error GoTo handelopenfile
Dim OpenFile As OPENFILENAME, Tempstr As String
Dim Success As Long, FileTitleLength%
Filter = Find_And_Replace(Filter, "|", Chr(0))
If Right$(Filter, 1) <> Chr(0) Then Filter = Filter & Chr(0)

OpenFile.lStructSize = Len(OpenFile)
OpenFile.hwndOwner = WindowHnd
OpenFile.hInstance = App.hInstance
OpenFile.lpstrFilter = Filter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(257, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile
OpenFile.lpstrTitle = Title
OpenFile.lpstrDefExt = DefaultExt
OpenFile.flags = 0
Success = GetOpenFileName(OpenFile)
If Success = 0 Then
GetOpenFileNameDLG = ""
Else
Tempstr = OpenFile.lpstrFile
GetOpenFileNameDLG = Trim(Tempstr)
End If
Exit Function
handelopenfile:
MsgBox Err.Description, 16, "Error " & Err.Number
Exit Function
End Function
Function Find_And_Replace(ByRef TextLine As String, ByRef SourceStr As String, ByRef ReplaceStr As String) As String
On Error GoTo handelfindandreplace
Dim DoAnother As Boolean, PosFound As Integer, ReturnStr As String
DoAnother = True
ReturnStr = TextLine
While DoAnother
PosFound = InStr(1, ReturnStr, SourceStr)
If PosFound > 0 Then
ReturnStr = Mid$(ReturnStr, 1, PosFound - 1) & ReplaceStr & Mid$(ReturnStr, PosFound + Len(SourceStr))
Else
DoAnother = False
End If
Wend
Find_And_Replace = ReturnStr
handelfindandreplace:
Exit Function
End Function

Rate Split any file into smaller files (101(101 Vote))
Split any file into smaller files.bas

Split any file into smaller files Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters