Results 1 to 4 of 4

Thread: Storing files as one

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421

    Question Storing files as one

    How do people store a lot of different pictures, texts, and sounds into one file? I've seen them all packed into one called a *.dat file but I have no clue how to do this myself, any ideas? I want all of my pictures and sounds packed into a *.dat file. Also, I would like to know how to load each one individually from the file, thanks.
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    You combine all the files into one file. You do it by working with the files in binary mode.
    I will write a function for that when I get time:0
    Baaaaaaaaah

  3. #3
    Megatron
    Guest
    I would use a structure similar the following.
    Code:
    Private Type BIGFILE
        nVideo As Long
        nSound As Long
        nMisc as Long
        bVideo() As Long
        bSound() As Long
        bMisc() As Long
    End Type
    The first 3 tell where that portion of the file ends, hence we know the size, and how much memory to allocate. For example. If nVideo was 1 000 000 bytes, then nVideo will store the number 1 000 000, and bVideo() will store the actual bytes. If you want to use predefined structures for common files (e.g: bitmap, wave etc.) you may do so, but just make sure you know the size.

  4. #4
    Fanatic Member stickman373's Avatar
    Join Date
    Mar 2001
    Location
    MA
    Posts
    909
    VB Code:
    1. Public Sub JoinFiles(TargetFile As String, ParamArray Files() As Variant)
    2.  
    3.     Dim iFFTarget As Integer, iFFSource As Integer, lFiles As Long, sRead As String
    4.     Dim sFileSizes As String, sFileData As String, sHeader As String
    5.  
    6.     iFFTarget = FreeFile
    7.     ' Clean/create the file:
    8.     Open TargetFile For Output As iFFTarget
    9.     Close iFFTarget
    10.  
    11.     iFFTarget = FreeFile
    12.     Open TargetFile For Binary As iFFTarget
    13.  
    14.     For lFiles = LBound(Files) To UBound(Files)
    15.         iFFSource = FreeFile
    16.        
    17.         Open Files(lFiles) For Binary As iFFSource
    18.             sRead = String(LOF(iFFSource), " ")
    19.             sFileSizes = sFileSizes & LOF(iFFSource) & "|" & Files(lFiles) & "|"
    20.             Get #iFFSource, , sRead
    21.         Close iFFSource
    22.         sFileData = sFileData & sRead
    23.     Next
    24.  
    25.     sHeader = Len(sFileSizes)
    26.     Put #iFFTarget, , sHeader & "</HEAD>"
    27.     Put #iFFTarget, , sFileSizes
    28.     Put #iFFTarget, , sFileData
    29.  
    30.     Close iFFTarget
    31.  
    32. End Sub
    33. Public Sub SplitFiles(FusedFile As String)
    34.  
    35.     Dim iFFFused As Integer, iFFSplit As Integer, sRead As String, lFiles As Long, lHeadSize As Long
    36.     Dim sFileSizes As String, sFiles() As String, sWrite As String, sSeek As String
    37.  
    38.     iFFFused = FreeFile
    39.     Open FusedFile For Binary As iFFFused
    40.         sRead = String(LOF(iFFFused), " ")
    41.         Get #iFFFused, , sRead
    42.        
    43.         lHeadSize = Split(sRead, "</HEAD>")(0)
    44.         sSeek = Trim(Str(lHeadSize)) & "</HEAD>"
    45.         sFileSizes = String(lHeadSize, " ")
    46.         Seek #iFFFused, 1
    47.         Get #iFFFused, , sSeek
    48.         Get #iFFFused, , sFileSizes
    49.         sFiles = Split(Left(sFileSizes, Len(sFileSizes) - 1), "|")
    50.         For lFiles = LBound(sFiles) To UBound(sFiles) Step 2
    51.             iFFSplit = FreeFile
    52.             sWrite = String(sFiles(lFiles), " ")
    53.             Get #iFFFused, , sWrite
    54.             Open sFiles(lFiles + 1) For Binary As iFFSplit
    55.                 Put #iFFSplit, , sWrite
    56.             Close iFFSplit
    57.         Next
    58.     Close iFFFused
    59.  
    60. End Sub
    61. Public Function RoundUp(Number As Double) As Long
    62.  
    63.     Dim lNumber As Long
    64.     lNumber = Number
    65.     If lNumber <> Number Then
    66.         RoundUp = lNumber + 1
    67.     Else
    68.         RoundUp = lNumber
    69.     End If
    70.  
    71. End Function

    use these functions written by gxparks

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