|
-
Oct 25th, 2001, 06:02 PM
#1
Thread Starter
Hyperactive Member
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]
-
Oct 25th, 2001, 06:48 PM
#2
PowerPoster
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
-
Oct 25th, 2001, 07:45 PM
#3
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.
-
Oct 25th, 2001, 07:52 PM
#4
Fanatic Member
VB Code:
Public Sub JoinFiles(TargetFile As String, ParamArray Files() As Variant)
Dim iFFTarget As Integer, iFFSource As Integer, lFiles As Long, sRead As String
Dim sFileSizes As String, sFileData As String, sHeader As String
iFFTarget = FreeFile
' Clean/create the file:
Open TargetFile For Output As iFFTarget
Close iFFTarget
iFFTarget = FreeFile
Open TargetFile For Binary As iFFTarget
For lFiles = LBound(Files) To UBound(Files)
iFFSource = FreeFile
Open Files(lFiles) For Binary As iFFSource
sRead = String(LOF(iFFSource), " ")
sFileSizes = sFileSizes & LOF(iFFSource) & "|" & Files(lFiles) & "|"
Get #iFFSource, , sRead
Close iFFSource
sFileData = sFileData & sRead
Next
sHeader = Len(sFileSizes)
Put #iFFTarget, , sHeader & "</HEAD>"
Put #iFFTarget, , sFileSizes
Put #iFFTarget, , sFileData
Close iFFTarget
End Sub
Public Sub SplitFiles(FusedFile As String)
Dim iFFFused As Integer, iFFSplit As Integer, sRead As String, lFiles As Long, lHeadSize As Long
Dim sFileSizes As String, sFiles() As String, sWrite As String, sSeek As String
iFFFused = FreeFile
Open FusedFile For Binary As iFFFused
sRead = String(LOF(iFFFused), " ")
Get #iFFFused, , sRead
lHeadSize = Split(sRead, "</HEAD>")(0)
sSeek = Trim(Str(lHeadSize)) & "</HEAD>"
sFileSizes = String(lHeadSize, " ")
Seek #iFFFused, 1
Get #iFFFused, , sSeek
Get #iFFFused, , sFileSizes
sFiles = Split(Left(sFileSizes, Len(sFileSizes) - 1), "|")
For lFiles = LBound(sFiles) To UBound(sFiles) Step 2
iFFSplit = FreeFile
sWrite = String(sFiles(lFiles), " ")
Get #iFFFused, , sWrite
Open sFiles(lFiles + 1) For Binary As iFFSplit
Put #iFFSplit, , sWrite
Close iFFSplit
Next
Close iFFFused
End Sub
Public Function RoundUp(Number As Double) As Long
Dim lNumber As Long
lNumber = Number
If lNumber <> Number Then
RoundUp = lNumber + 1
Else
RoundUp = lNumber
End If
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|