s1ckOh
Well-known member
Hello,
I'm working on trying to split a large file from say 3gb to multiple 500mb files with a .1, .2, .3 etc... extension.
My output is one 500mb file and one 28kb file. I can't figure out what I'm missing to continue reading the filestream into the 2nd split file.
here is my code so far... Thanks in advance for any ideas.
Sub SplitFiles(ByVal inFile As String, ByVal newFileSizeBytes As Integer)
Dim i As Short = 1
Dim fsInput As New System.IO.FileStream(inFile, FileMode.Open, FileAccess.Read)
Dim fsOutput As System.IO.FileStream
Dim bytBuffer(4096) As Byte 'holds a block of bytes for processing
Dim lngBytesProcessed As Long = 0 'running count of bytes processed
Dim lngFileLength As Long = fsInput.Length 'the input file's length
Dim intBytesInCurrentBlock As Integer 'current bytes being processed
Try
While lngBytesProcessed < lngFileLength
fsOutput = New FileStream(inFile & "." & i, FileMode.OpenOrCreate, FileAccess.Write)
'Make sure fsOutput is empty
fsOutput.SetLength(0)
'Set progress bar min/max
pbStatus.Value = 0
pbStatus.Maximum = 10000
While fsOutput.Length < newFileSizeBytes
'Read file with the input filestream.
intBytesInCurrentBlock = fsInput.Read(bytBuffer, 0, 4096)
'Write output file
fsOutput.Write(bytBuffer, 0, intBytesInCurrentBlock)
'Update lngBytesProcessed
lngBytesProcessed = lngBytesProcessed + CLng(intBytesInCurrentBlock)
'Update Progress Bar
pbStatus.Value = CInt((lngBytesProcessed / newFileSizeBytes) * 10000)
End While
'Close FileStream
fsOutput.Close()
i += 1
End While
fsInput.Close()
Catch
End Try
End Sub
I'm working on trying to split a large file from say 3gb to multiple 500mb files with a .1, .2, .3 etc... extension.
My output is one 500mb file and one 28kb file. I can't figure out what I'm missing to continue reading the filestream into the 2nd split file.
here is my code so far... Thanks in advance for any ideas.
Sub SplitFiles(ByVal inFile As String, ByVal newFileSizeBytes As Integer)
Dim i As Short = 1
Dim fsInput As New System.IO.FileStream(inFile, FileMode.Open, FileAccess.Read)
Dim fsOutput As System.IO.FileStream
Dim bytBuffer(4096) As Byte 'holds a block of bytes for processing
Dim lngBytesProcessed As Long = 0 'running count of bytes processed
Dim lngFileLength As Long = fsInput.Length 'the input file's length
Dim intBytesInCurrentBlock As Integer 'current bytes being processed
Try
While lngBytesProcessed < lngFileLength
fsOutput = New FileStream(inFile & "." & i, FileMode.OpenOrCreate, FileAccess.Write)
'Make sure fsOutput is empty
fsOutput.SetLength(0)
'Set progress bar min/max
pbStatus.Value = 0
pbStatus.Maximum = 10000
While fsOutput.Length < newFileSizeBytes
'Read file with the input filestream.
intBytesInCurrentBlock = fsInput.Read(bytBuffer, 0, 4096)
'Write output file
fsOutput.Write(bytBuffer, 0, intBytesInCurrentBlock)
'Update lngBytesProcessed
lngBytesProcessed = lngBytesProcessed + CLng(intBytesInCurrentBlock)
'Update Progress Bar
pbStatus.Value = CInt((lngBytesProcessed / newFileSizeBytes) * 10000)
End While
'Close FileStream
fsOutput.Close()
i += 1
End While
fsInput.Close()
Catch
End Try
End Sub