Results 1 to 6 of 6

Thread: File Splitter * resolved

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    File Splitter * resolved

    Can someone pls give me a simple code for a file splitter program that can split a file into 100kb chunks? Better if the file can be reassembled at the DOS prompt by; copy chunk1 + chunk2 + ... etc.

    I don't have time to make this because I'm working on something else. I need this code to split my 1.2MB file so it doesn't time out when I try to attach it to my yahoo mail. I need to send the file ASAP.

    I know I should work on this myself but I'm not good at working with binary data and this is urgent. I don't have time to learn binary manipuation, test and debug it. PLEASE!! HELP!!
    Last edited by leinad31; Feb 12th, 2003 at 01:03 PM.

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    leinad31


    Will this be a flat rate or per diem assignment!!!!!


    Now really????

  3. #3
    Hyperactive Member nazeem_khan's Avatar
    Join Date
    Nov 2002
    Location
    India
    Posts
    305

    Re: File Splitter

    Originally posted by leinad31
    Can someone pls give me a simple code for a file splitter program that can split a file into 100kb chunks? Better if the file can be reassembled at the DOS prompt by; copy chunk1 + chunk2 + ... etc.

    I don't have time to make this because I'm working on something else. I need this code to split my 1.2MB file so it doesn't time out when I try to attach it to my yahoo mail. I need to send the file ASAP.

    I know I should work on this myself but I'm not good at working with binary data and this is urgent. I don't have time to learn binary manipuation, test and debug it. PLEASE!! HELP!!
    goto www.planetsourcecode.com and search for it..

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    randem: Ouch! No this is not an assignment. I know there are file splitter programs but I don't want to go to the trouble of seeing if you also need the program at the recipient to merge the file. I used to have a program in TC before my HDD crashed and it merged the file with DOS copy command. But I already passed my TC programming days and I don't have time to refresh myself.


    nazeem_khan: I'm downloading it as I type. Hopefully this allows the file to be merged at the DOS prompt so I don't have to explain to the recipient how to merge the file.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Ok. It works, it has the batch file. Sorry for the out of context question. Didn't know where to ask.

  6. #6
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    I made this in the last hour or so... it can join and split multiple files, and it works in DOS (edit: command prompt I mean) too....

    for example
    FileSplit -split -2files "testfile1.dat" "testfile2.dat"

    it will output:
    testfile1.dat.split001
    testfile1.dat.split002

    testfile2.dat.split001
    testfile2.dat.split002

    VB Code:
    1. Option Explicit
    2. Option Compare Text ' for the Like operator
    3.  
    4. Private Enum IfStringNotFound
    5.     ReturnOriginalStr = 0
    6.     ReturnEmptyStr = 1
    7. End Enum
    8.  
    9. Private Sub Form_Load()
    10.     Dim CMD As String, Command1 As String, Command2 As String
    11.     Dim FileNames As Collection, K As Variant, SplitBytes As Long
    12.     Dim Buffer As String, FileCount As Integer
    13.    
    14.     Me.Hide
    15.    
    16.     On Error GoTo ErrExit
    17.     CMD = Trim(Command)
    18.     If CMD = "" Then
    19.         MsgBox "Format examples:" & vbNewLine & _
    20.             "FileSplit -split -2files ""TestFile.dat""" & vbNewLine & _
    21.             "FileSplit -split -700kbytes ""TestFile.dat""" & vbNewLine & _
    22.             "FileSplit -split -3mbytes ""TestFile.dat""" & vbNewLine & _
    23.             "FileSplit -join ""TestFile.dat.split001"" ""TestFile.dat.split002"""
    24.         Unload Me
    25.         Exit Sub
    26.     End If
    27.    
    28.     Command1 = LeftRight(CMD, "-", , ReturnEmptyStr)
    29.     Command2 = LeftLeft(LeftRight(Command1, "-", , ReturnEmptyStr), " ")
    30.     Command1 = LeftLeft(Command1, " ")
    31.    
    32.     ' Command1 should contain either "split" or "join" without qwotes
    33.    
    34.     Set FileNames = GetFileNames(LeftRight(RightRight(CMD, "-", , ReturnEmptyStr), " "))
    35.    
    36.     If FileNames Is Nothing Then
    37.         MsgBox "No files selected", vbExclamation
    38.         Unload Me
    39.         Exit Sub
    40.     End If
    41.    
    42.     If Command1 Like "*split*" Then ' split into files
    43.         For Each K In FileNames
    44.             If Command2 Like "#*files*" Then ' splits file in # files
    45.                 SplitBytes = FileLen(CStr(K)) / Val(Command2) ' calculate how many bytes in one file
    46.             ElseIf Command2 Like "#*kbytes" Then
    47.                 SplitBytes = Val(Command2) * 1024& ' size is given in Kilo Bytes
    48.             ElseIf Command2 Like "#*mbytes" Then
    49.                 SplitBytes = Val(Command2) * 1048576 ' size is given in Mega Bytes
    50.             ElseIf Command2 Like "#*bytes" Then
    51.                 SplitBytes = Val(Command2) ' size is given in Bytes
    52.             End If
    53.            
    54.             Open CStr(K) For Binary Access Read As #1
    55.                 Do
    56.                     If Loc(1) + SplitBytes > LOF(1) Then
    57.                         Buffer = String(LOF(1) - Loc(1), 0) ' if last file, do only remaining bytes
    58.                     Else
    59.                         Buffer = String(SplitBytes, 0)
    60.                     End If
    61.                    
    62.                     Get #1, , Buffer
    63.                    
    64.                     FileCount = FileCount + 1
    65.                     Open CStr(K) & ".split" & Right("000" & FileCount, 3) For Binary Access Write As #2
    66.                         Put #2, , Buffer
    67.                     Close #2
    68.                 Loop Until Loc(1) >= LOF(1)
    69.             Close #1
    70.         Next
    71.     ElseIf Command1 Like "*join*" Then ' join files
    72.         Dim Q As Integer, P As Integer, TmpStr As String
    73.         Dim ArrFileNames() As String, BaseFile As String
    74.        
    75.         ' can't sort the items in the Collection, so have to transfer into String array
    76.         ReDim ArrFileNames(FileNames.Count - 1)
    77.        
    78.         For Q = 0 To UBound(ArrFileNames)
    79.             ArrFileNames(Q) = FileNames(Q + 1)
    80.         Next Q
    81.        
    82.         ' sort the files, to make sure the data will be joined back in the right order
    83.         For Q = 0 To UBound(ArrFileNames)
    84.             For P = Q To UBound(ArrFileNames)
    85.                 If ArrFileNames(Q) > ArrFileNames(P) Then
    86.                     TmpStr = ArrFileNames(Q)
    87.                     ArrFileNames(Q) = ArrFileNames(P)
    88.                     ArrFileNames(P) = TmpStr
    89.                 End If
    90.             Next P
    91.         Next Q
    92.        
    93.         Do Until FileNames.Count = 0
    94.             FileNames.Remove 1
    95.         Loop
    96.        
    97.         ' put the filenames back into the collection in the right order
    98.         For Q = 0 To UBound(ArrFileNames)
    99.             FileNames.Add ArrFileNames(Q)
    100.         Next Q
    101.        
    102.         ' now they are in the right order, and ready to put them together
    103.        
    104.         Do Until FileNames.Count = 0
    105.             BaseFile = RightLeft(FileNames(1), ".split", , ReturnEmptyStr)
    106.            
    107.             Open BaseFile For Binary Access Write As #1
    108.                 Do While (CStr(FileNames(1)) Like BaseFile & "*")
    109.                     Open CStr(FileNames(1)) For Binary Access Read As #2
    110.                         Buffer = String(LOF(2), 0)
    111.                         Get #2, , Buffer
    112.                     Close #2
    113.                    
    114.                     Put #1, , Buffer
    115.                     FileNames.Remove 1
    116.                     If FileNames.Count = 0 Then Exit Do
    117.                 Loop
    118.             Close #1
    119.         Loop
    120.     Else
    121.         MsgBox "Unknown command.", vbExclamation
    122.     End If
    123.    
    124.     Unload Me
    125.     Exit Sub
    126. ErrExit:
    127.     MsgBox "Unexpected error !" & vbNewLine & _
    128.         "Error: " & Err.Number & vbNewLine & _
    129.         "Description: " & Err.Description, vbCritical, "Error"
    130.    
    131.     Err.Clear
    132.     Unload Me
    133.     Exit Sub
    134. End Sub
    135.  
    136. Private Function GetFileNames(ByVal CMD As String) As Collection
    137.     Dim FileName As String
    138.     If Trim(CMD) = "" Then Exit Function
    139.    
    140.     On Error GoTo ErrResize
    141.     Do Until Trim(CMD) = ""
    142.         CMD = LeftRight(CMD, """", , ReturnEmptyStr)
    143.         FileName = LeftLeft(CMD, """", , ReturnEmptyStr)
    144.         CMD = LeftRight(CMD, """", , ReturnEmptyStr)
    145.        
    146.         If Dir(FileName, vbHidden Or vbArchive) <> "" Then
    147.             If GetFileNames Is Nothing Then Set GetFileNames = New Collection
    148.             GetFileNames.Add FileName
    149.         End If
    150.     Loop
    151.    
    152.     Exit Function
    153. ErrResize:
    154.     MsgBox "Unexpected error !" & vbNewLine & _
    155.         "Error: " & Err.Number & vbNewLine & _
    156.         "Description: " & Err.Description, vbCritical, "Error"
    157.     Err.Clear
    158.     Exit Function
    159. End Function
    160.  
    161. Private Function LeftLeft(ByRef Str As String, LFind As String, Optional Compare As VbCompareMethod = vbBinaryCompare, Optional RetError As IfStringNotFound = ReturnOriginalStr) As String
    162.     Dim K As Long
    163.    
    164.     K = InStr(1, Str, LFind, Compare)
    165.     If K = 0 Then
    166.         LeftLeft = IIf(RetError = ReturnOriginalStr, Str, "")
    167.     Else
    168.         LeftLeft = Left(Str, K - 1)
    169.     End If
    170. End Function
    171.  
    172. Private Function LeftRight(ByRef Str As String, LFind As String, Optional Compare As VbCompareMethod = vbBinaryCompare, Optional RetError As IfStringNotFound = ReturnOriginalStr) As String
    173.     Dim K As Long
    174.    
    175.     K = InStr(1, Str, LFind, Compare)
    176.     If K = 0 Then
    177.         LeftRight = IIf(RetError = ReturnOriginalStr, Str, "")
    178.     Else
    179.         LeftRight = Right(Str, (Len(Str) - Len(LFind)) - K + 1)
    180.     End If
    181. End Function
    182.  
    183. Private Function RightLeft(ByRef Str As String, RFind As String, Optional Compare As VbCompareMethod = vbBinaryCompare, Optional RetError As IfStringNotFound = ReturnOriginalStr) As String
    184.     Dim K As Long
    185.    
    186.     K = InStrRev(Str, RFind, , Compare)
    187.    
    188.     If K = 0 Then
    189.         RightLeft = IIf(RetError = ReturnOriginalStr, Str, "")
    190.     Else
    191.         RightLeft = Left(Str, K - 1)
    192.     End If
    193. End Function
    194.  
    195. Private Function RightRight(ByRef Str As String, RFind As String, Optional Compare As VbCompareMethod = vbBinaryCompare, Optional RetError As IfStringNotFound = ReturnOriginalStr) As String
    196.     Dim K As Long
    197.    
    198.     K = InStrRev(Str, RFind, , Compare)
    199.    
    200.     If K = 0 Then
    201.         RightRight = IIf(RetError = ReturnOriginalStr, Str, "")
    202.     Else
    203.         RightRight = Mid(Str, K + 1, Len(Str))
    204.     End If
    205. End Function
    Attached Files Attached Files
    Last edited by CVMichael; Feb 12th, 2003 at 04:09 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width