AddPackFile()
Syntax
Result = AddPackFile(#Pack, Filename$, PackedFilename$)Description
Add and compress the file to the specified pack previously created with CreatePack(). Adding a large file can take a long time.
Parameters
#Pack The pack to use. Filename$ The filename$ to add to the pack. PackedFilename$ The filename to use in the archive to store the file.
Return value
Nonzero if the file has been successfully added to the packfile. If the file can't be compressed, it will be stored as is in the packfile.
Example: Using a tree file structure
UseZipPacker() Path$ = "C:/ProgramData/PureBasic/Examples/Sources/" ; path to the PureBasic examples source files PackFile$ = "C:/ProgramData/PureBasic/Examples/MyCompressedFiles.zip" ; path to the pack file which should be created and opened later If CreatePack(0, PackFile$) AddPackFile(0, Path$ + "Data/world.png", "Data/world.png") AddPackFile(0, Path$ + "Data/test.pref", "Data/test.pref") AddPackFile(0, Path$ + "Data/CdPlayer.ico", "Data/CdPlayer.ico") AddPackFile(0, Path$ + "2DDrawing.pb", "2DDrawing.pb") ClosePack(0) Debug "PackFile successfully created: " + PackFile$ Else Debug "Error creating the pack file!" EndIf Path$ = "C:/ProgramData/PureBasic/Examples/test_delete/" ; path to a directory into which the pack files should be extracted If OpenPack(0, PackFile$) If (CreateDirectory(Path$) And CreateDirectory(Path$ + "Data/")) Or FileSize(Path$ + "Data/") = -2 If ExaminePack(0) Debug "Archive contents to be unpacked:" While NextPackEntry(0) Debug " - name: " + PackEntryName(0) + ", size: " + PackEntrySize(0) If UncompressPackFile(0, Path$ + PackEntryName(0), PackEntryName(0)) = -1 Debug "Error: unsuccessful unpacking of file: " + PackEntryName(0) EndIf Wend Else Debug "Error examining the pack file!" EndIf ClosePack(0) RunProgram(Path$) ; open the directory with the unpacked files Else Debug "Error while creating the folder to unpack the archive contents!" EndIf Else Debug "Error opening the pack file!" EndIfFor another example see UncompressPackFile().
See Also
CreatePack()
Supported OS
All