home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
- Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "Comdlg32.ocx"
- Begin VB.Form frmMain
- BorderStyle = 1 'Fixed Single
- Caption = "File Splitter"
- ClientHeight = 3315
- ClientLeft = 45
- ClientTop = 330
- ClientWidth = 3765
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 3315
- ScaleWidth = 3765
- StartUpPosition = 2 'CenterScreen
- Begin VB.ComboBox cmbSplitSize
- Height = 315
- Left = 120
- Style = 2 'Dropdown List
- TabIndex = 10
- Top = 960
- Width = 1335
- End
- Begin VB.Frame fraStats
- Caption = "Statistics"
- Height = 1335
- Left = 120
- TabIndex = 6
- Top = 1800
- Width = 3495
- Begin VB.Label lblFileCount
- AutoSize = -1 'True
- Caption = "File Count:"
- Height = 195
- Left = 120
- TabIndex = 12
- Top = 240
- Width = 750
- End
- Begin VB.Label lblElapsed
- AutoSize = -1 'True
- Caption = "Elapsed Time:"
- Height = 195
- Left = 120
- TabIndex = 9
- Top = 960
- Width = 1005
- End
- Begin VB.Label lblFinish
- AutoSize = -1 'True
- Caption = "Finish Time:"
- Height = 195
- Left = 120
- TabIndex = 8
- Top = 720
- Width = 840
- End
- Begin VB.Label lblStart
- AutoSize = -1 'True
- Caption = "Start Time:"
- Height = 195
- Left = 120
- TabIndex = 7
- Top = 480
- Width = 765
- End
- End
- Begin VB.CommandButton cmdBrowse
- Caption = "..."
- Height = 255
- Left = 3360
- TabIndex = 4
- Top = 360
- Width = 255
- End
- Begin VB.TextBox txtFileName
- Height = 285
- Left = 120
- TabIndex = 3
- Top = 360
- Width = 3135
- End
- Begin VB.CommandButton cmdJoin
- Caption = "Join File"
- Enabled = 0 'False
- Height = 375
- Left = 2640
- TabIndex = 2
- Top = 960
- Width = 975
- End
- Begin MSComctlLib.ProgressBar ProgressBar1
- Height = 255
- Left = 120
- TabIndex = 1
- Top = 1440
- Width = 3495
- _ExtentX = 6165
- _ExtentY = 450
- _Version = 393216
- Appearance = 1
- Scrolling = 1
- End
- Begin VB.CommandButton cmdSplit
- Caption = "Split File"
- Default = -1 'True
- Enabled = 0 'False
- Height = 375
- Left = 1560
- TabIndex = 0
- Top = 960
- Width = 975
- End
- Begin MSComDlg.CommonDialog CommonDialog1
- Left = 3120
- Top = 120
- _ExtentX = 847
- _ExtentY = 847
- _Version = 393216
- End
- Begin VB.Label lblSplitSize
- AutoSize = -1 'True
- Caption = "Split Size (KB)"
- Height = 195
- Left = 120
- TabIndex = 11
- Top = 720
- Width = 990
- End
- Begin VB.Label lblFileName
- AutoSize = -1 'True
- Caption = "Filename:"
- Height = 195
- Left = 120
- TabIndex = 5
- Top = 120
- Width = 675
- End
- Attribute VB_Name = "frmMain"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Public Function SplitFiles(ByVal inputFilename As String, newFileSizeBytes As Long) As Boolean
- Dim fReadHandle As Long
- Dim fWriteHandle As Long
- Dim fSuccess As Long
- Dim lBytesWritten As Long
- Dim lBytesRead As Long
- Dim ReadBuffer() As Byte
- Dim TotalCount As Long
- Dim StartTime As Date
- Dim FinishTime As Date
- Dim StartTimeDouble As Double
- Dim FinishTimeDouble As Double
- Dim Count As Integer
- ' User Interface Stuff
- StartTime = Now
- StartTimeDouble = getTime
- Me.MousePointer = vbHourglass
- cmdJoin.Enabled = False
- cmdSplit.Enabled = False
- lblStart = "Start Time: " & StartTime
- ProgressBar1.Max = FileLen(inputFilename)
- ProgressBar1.Value = 0
- Count = 1
- ' Resize Byte Array for Read
- ReDim ReadBuffer(0 To newFileSizeBytes)
-
- ' Determine Total Number of Output Files for User Interface Only
- TotalCount = (FileLen(inputFilename) \ UBound(ReadBuffer)) + 1
- ' Open Read File Handle
- fReadHandle = CreateFile(inputFilename, GENERIC_WRITE Or GENERIC_READ, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
- ' If Successful read, continue
- If fReadHandle <> INVALID_HANDLE_VALUE Then
- ' Read First File Block
- fSuccess = ReadFile(fReadHandle, ReadBuffer(0), UBound(ReadBuffer), lBytesRead, 0)
-
- ' Increment ProgressBar
- ProgressBar1.Value = ProgressBar1.Value + lBytesRead
- ProgressBar1.Refresh
-
- ' Loop while not EOF
- Do While lBytesRead > 0
- ' Update File Count Statistic on User Interface
- lblFileCount.Caption = "Split Count: " & Count & " of " & TotalCount
- lblFileCount.Refresh
-
- ' Open Write File Handle
- If Dir(inputFilename & "." & Count) <> "" Then
- Kill inputFilename & "." & Count
- End If
- fWriteHandle = CreateFile(inputFilename & "." & Count, GENERIC_WRITE Or GENERIC_READ, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
- ' If Successful Write, Continue
- If fWriteHandle <> INVALID_HANDLE_VALUE Then
- ' Write Data Block to File
- fSuccess = WriteFile(fWriteHandle, ReadBuffer(0), lBytesRead, lBytesWritten, 0)
- If fSuccess <> 0 Then
- ' Required to Write to File
- fSuccess = FlushFileBuffers(fWriteHandle)
- ' Close Write File
- fSuccess = CloseHandle(fWriteHandle)
- Else
- ' On Failure Quit
- lblFileCount.Caption = "Split Count: Write Error"
- SplitFiles = False
- Exit Function
- End If
- Else
- ' On Failure Quit
- lblFileCount.Caption = "Split Count: Write Error"
- SplitFiles = False
- Exit Function
- End If
- ' Get the next Read Block
- fSuccess = ReadFile(fReadHandle, ReadBuffer(0), UBound(ReadBuffer), lBytesRead, 0)
-
- ' Increment ProgressBar
- ProgressBar1.Value = ProgressBar1.Value + lBytesRead
- ProgressBar1.Refresh
-
- ' Increment Count
- Count = Count + 1
- Loop
- ' Close Read File
- fSuccess = CloseHandle(fReadHandle)
- Else
- ' On Failure Quit
- lblFileCount.Caption = "Split Count: Read Error"
- SplitFiles = False
- Exit Function
- End If
- ' User Interface Stuff
- ProgressBar1.Value = ProgressBar1.Max
- lblFileCount.Caption = "Split Count: Finished (" & Count - 1 & " Files)"
- FinishTime = Now
- FinishTimeDouble = getTime
- lblFinish = "Finish Time: " & FinishTime
- lblElapsed = "Elapsed Time: " & Format(FinishTimeDouble - StartTimeDouble, "#.00") & " seconds"
- Call txtFileName_Change
- Me.MousePointer = vbDefault
- SplitFiles = True
- End Function
- Public Function JoinFiles(ByVal inputFilename As String) As Boolean
- Dim fReadHandle As Long
- Dim fWriteHandle As Long
- Dim fSuccess As Long
- Dim lBytesWritten As Long
- Dim lBytesRead As Long
- Dim ReadBuffer() As Byte
- Dim TotalCount As Long
- Dim StartTime As Date
- Dim FinishTime As Date
- Dim StartTimeDouble As Double
- Dim FinishTimeDouble As Double
- Dim Count As Integer
- Dim FileName As String
- Dim ret As Integer
- ' Check for existing Output File
- If Dir(inputFilename) <> "" Then
- ret = MsgBox("Output file (" & inputFilename & ") already exists." & vbCr & "Are you sure you want to overwrite it?", vbYesNo + vbQuestion, "Overwrite Warning")
- If ret = vbNo Then
- lblFileCount.Caption = "Join Count: Output File Exists"
- JoinFiles = False
- Exit Function
- Else
- Kill inputFilename
- End If
- End If
-
- ' Determine how many split files are contained in the entire set
- Count = 1
- FileName = Dir(inputFilename & ".1")
- If FileName = "" Then
- lblFileCount.Caption = "Join Count: No Input Files"
- JoinFiles = False
- Exit Function
- End If
- ProgressBar1.Value = 0
- ProgressBar1.Max = FileLen(inputFilename & ".1")
- Do While FileName <> ""
- Count = Count + 1
- FileName = Dir(inputFilename & "." & Count)
- If FileName <> "" Then
- ProgressBar1.Max = ProgressBar1.Max + FileLen(inputFilename & "." & Count)
- End If
- Loop
- TotalCount = Count - 1
- ' User Interface Stuff
- StartTime = Now
- StartTimeDouble = getTime
- Me.MousePointer = vbHourglass
- cmdJoin.Enabled = False
- cmdSplit.Enabled = False
- lblStart = "Start Time: " & StartTime
- ' Open Write File Handle
- fWriteHandle = CreateFile(inputFilename, GENERIC_WRITE Or GENERIC_READ, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
- ' If Successful Write, Continue
- If fWriteHandle <> INVALID_HANDLE_VALUE Then
- For Count = 1 To TotalCount
- ' Open Read File Handle
- ReDim ReadBuffer(0 To FileLen(inputFilename & "." & Count))
- fReadHandle = CreateFile(inputFilename & "." & Count, GENERIC_WRITE Or GENERIC_READ, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
-
- ' If Successful read, continue
- If fReadHandle <> INVALID_HANDLE_VALUE Then
- ' Read First File Block
- fSuccess = ReadFile(fReadHandle, ReadBuffer(0), UBound(ReadBuffer), lBytesRead, 0)
-
- ' Write Data Block to File
- fSuccess = WriteFile(fWriteHandle, ReadBuffer(0), UBound(ReadBuffer), lBytesWritten, 0)
- If fSuccess <> 0 Then
- ' Required to Write to File
- fSuccess = FlushFileBuffers(fWriteHandle)
- Else
- ' On Failure Quit
- lblFileCount.Caption = "Join Count: Write Error"
- JoinFiles = False
- Exit Function
- End If
-
- fSuccess = CloseHandle(fReadHandle)
-
- ' Increment ProgressBar
- ProgressBar1.Value = ProgressBar1.Value + lBytesWritten
- ProgressBar1.Refresh
-
- ' Update File Count Statistic on User Interface
- lblFileCount.Caption = "Join Count: " & Count & " of " & TotalCount
- lblFileCount.Refresh
- Else
- ' On Failure Quit
- lblFileCount.Caption = "Join Count: Read Error"
- JoinFiles = False
- Exit Function
- End If
-
- Next Count
- Else
- ' On Failure Quit
- lblFileCount.Caption = "Join Count: Write Error"
- JoinFiles = False
- Exit Function
- End If
- ' Close Write File
- fSuccess = CloseHandle(fWriteHandle)
-
- ' User Interface Stuff
- ProgressBar1.Value = ProgressBar1.Max
- lblFileCount.Caption = "File Count: Finished (" & Count - 1 & " Files)"
- FinishTime = Now
- FinishTimeDouble = getTime
- lblFinish = "Finish Time: " & FinishTime
- lblElapsed = "Elapsed Time: " & Format(FinishTimeDouble - StartTimeDouble, "#.00") & " seconds"
- Call txtFileName_Change
- Me.MousePointer = vbDefault
- End Function
- Private Sub cmdBrowse_Click()
- On Error GoTo e_cmdBrowse
- CommonDialog1.CancelError = True
- Call CommonDialog1.ShowOpen
- txtFileName = CommonDialog1.FileName
- Exit Sub
- e_cmdBrowse:
- Exit Sub
- End Sub
- Private Sub cmdJoin_Click()
- If txtFileName <> "" And Dir(txtFileName & ".1") <> "" Then
- Call JoinFiles(txtFileName)
- Else
- Call txtFileName_Change
- Call MsgBox("File Not Found (" & txtFileName & ")", vbOKOnly + vbCritical, "File Read Error")
- End If
- End Sub
- Private Sub cmdSplit_Click()
- If txtFileName <> "" And Dir(txtFileName) <> "" Then
- Call SplitFiles(txtFileName, CLng(cmbSplitSize.Text) * CLng(1024))
- Else
- Call txtFileName_Change
- Call MsgBox("File Not Found (" & txtFileName & ")", vbOKOnly + vbCritical, "File Read Error")
- End If
- End Sub
- Private Sub Form_Load()
- cmbSplitSize.Clear
- cmbSplitSize.AddItem ("1")
- cmbSplitSize.AddItem ("2")
- cmbSplitSize.AddItem ("5")
- cmbSplitSize.AddItem ("10")
- cmbSplitSize.AddItem ("50")
- cmbSplitSize.AddItem ("100")
- cmbSplitSize.AddItem ("500")
- cmbSplitSize.AddItem ("1000")
- cmbSplitSize.AddItem ("1440")
- cmbSplitSize.AddItem ("2000")
- cmbSplitSize.ListIndex = 7
- End Sub
- Private Sub txtFileName_Change()
- If txtFileName <> "" And Dir(txtFileName) <> "" Then
- cmdSplit.Enabled = True
- Else
- cmdSplit.Enabled = False
- End If
- If txtFileName <> "" And Dir(txtFileName & ".1") <> "" Then
- cmdJoin.Enabled = True
- Else
- cmdJoin.Enabled = False
- End If
- End Sub
-