Page 1 of 1

Posted: Fri Aug 09, 2002 7:45 pm
by BackupUser
Restored from previous forum. Originally posted by scurrier.

does the AddPackFile keep the file name with it?

here's what i am trying to do i need to pack the contents of a directory
with 5-10 files in it and then unpack later

is there a UnpackFile command if not how do i unpack each file with the correct name. I have read alot of the forums but i just can't seem to unpack my packed file. here is what i have done so far

Procedure packDir(SourceDirectory$,start)
If ExamineDirectory(Start, SourceDirectory$, "*.*")
Repeat
Type = NextDirectoryEntry()
If Type = 2
If DirectoryEntryName() "." And DirectoryEntryName() ".."

EndIf
Else
If Type = 1
sfile.s=SourceDirectory$+"\"+DirectoryEntryName()
cpy=AddPackFile(sfile.s)
Debug cpy
Debug sfile

EndIf
EndIf
Until Type = 0
EndIf
EndProcedure



GetTime()
year.s=Str(Year())
month.s=Str(Month())
day.s=Str(Day())
mn=Len(month)
If mn=1
month="0"+month
EndIf
dy=Len(day)
If dy=1
day="0"+day
EndIf

filecode.s=month+day+year
SourceDirectory$="d:\mssql\backup"
dest$=SourceDirectory$+"\Psoft8"+filecode+".stf"

;CreatePack(dest$)
;packDir(SourceDirectory$,start)
;ClosePack()
OpenPack(dest$)
Repeat
MemoryAddress = NextPackFile()
Size = PackFileSize()
;Debug Size
Debug MemoryAddress
DecompressedLength = UnpackMemory(UseMemory(0), UseMemory(1))
If DecompressedLength = OriginalLenght
OpenFile(1,"Temp.unpack")
WriteData(UseMemory(1),DecompressedLength)
CloseFile(1)
EndIf
Until MemoryAddress=0
ClosePack()

Thanks
Sean

Posted: Sat Aug 10, 2002 5:01 am
by BackupUser
Restored from previous forum. Originally posted by Danilo.

Change your pack-procedure to include the filename:

Code: Select all

Procedure packDir(SourceDirectory$,start)
 If ExamineDirectory(Start, SourceDirectory$, "*.*")
   Repeat
     Type = NextDirectoryEntry()
     If Type = 2
        If DirectoryEntryName()  "." And DirectoryEntryName()  ".."
        EndIf
     Else
        If Type = 1
           sfile.s=SourceDirectory$+"\"+DirectoryEntryName()
           AddPackMemory(@sfile,Len(sfile)+1)                 ; ADD FILENAME
           cpy=AddPackFile(sfile.s) 
          Debug cpy
          Debug sfile
        EndIf
     EndIf
   Until Type = 0
 EndIf
EndProcedure
So your packed file looks like this:
Filename1$, File1, Filename2$, File2, ...

If you unpack, you get the filename first
(use PeekS() to get it in a string ) and
after that the file.

cya,
...Danilo

(registered PureBasic user)

Posted: Mon Aug 12, 2002 5:42 pm
by BackupUser
Restored from previous forum. Originally posted by scurrier.

thanks that helps a lot