Structure typZipLocalFileHead ; 30 bytes
zlfhSignature.l; As Long ' 0x04034B50
zlfhVersion.w; As Integer
zlfhBitFlag.w; As Integer
zlfhCompression.w; As Integer
zlfhModFileTime.w; As Integer
zlfhModFileData.w; As Integer
zlfhCRC.l; As Long
zlfhCompressedSize.l; As Long
zlfhUncompressedSize.l; As Long
zlfhFileNameLength.w; As Integer
zlfhExtraFieldLength.w; As Integer
EndStructure
Procedure ListZipFile(Filename.s)
ReadHead.typZipLocalFileHead
FF=ReadFile(#PB_Any,Filename)
If FF
again:
ReadHead\zlfhSignature= ReadLong(ff)
If ReadHead\zlfhSignature=$4034B50
;Debug "valid Zip File!"
FileSeek(FF,Loc(ff)-4)
;Debug Loc(FF)
Laenge = ReadData(FF, @ReadHead, SizeOf(ReadHead))
;Debug Loc(FF)
With ReadHead
; Get the file name
If \zlfhFileNameLength<>0
FileString.s = Space(\zlfhFileNameLength)
;Debug Loc(FF)
Laenge = ReadData(FF, @FileString, \zlfhFileNameLength)
;Debug Loc(FF)
Debug Filestring
EndIf
Debug" Compressed=" + Str(\zlfhCompressedSize) + " UnCompressed=" + Str(\zlfhUnCompressedSize)
;Debug \zlfhExtraFieldLength
;Debug \zlfhBitFlag
; Work out how much extra Data To skip over
SeekSize = \zlfhCompressedSize
If \zlfhExtraFieldLength
SeekSize + \zlfhExtraFieldLength
EndIf
If (\zlfhBitFlag & $4)
SeekSize + 12
EndIf
;Debug Seeksize
EndWith
;Seek To Next record
Seeksize + Loc(FF)
;Debug Seeksize
FileSeek(FF,Seeksize)
; Increment file count
Filecount + 1
Goto again
Else
Debug "no more entries in ZIP"
EndIf
Debug Str(Filecount) + " in ZipFile"
CloseFile(FF)
EndIf
EndProcedure
FileName.s= "c:\B0712021_Botek_Werk3_HMI.zip"
ListZipFile(FileName)
changed code to open file readonly
Last edited by Rings on Fri Jul 25, 2008 1:39 pm, edited 3 times in total.
Thanks for translating this Visual Basic code, but it doesn't seem to work yet?
At least not with any zip files that I tested it with. I get no debug output at all.
PB wrote:Thanks for translating this Visual Basic code, but it doesn't seem to work yet?
At least not with any zip files that I tested it with. I get no debug output at all.
what would you espect from a quick VB port from me ?
anyway, can you post the zipfiles that did not work ?
(mine here works okay)
NViewLib/
Compressed=0 UnCompressed=0
NViewLib/NViewLib.dll
Compressed=132009 UnCompressed=265216
NViewLib/NViewLib.rtf
Compressed=4540 UnCompressed=18723
no valid ZIP
3 in ZipFile
The Goto thing was a joke. But since there was a reaction, how could the
code be modified NOT to use it, since so many people say that any code can
be written without Goto if they really wanted to. To those people: show me.
Structure typZipLocalFileHead ; 30 bytes
zlfhSignature.l; As Long ' 0x04034B50
zlfhVersion.w; As Integer
zlfhBitFlag.w; As Integer
zlfhCompression.w; As Integer
zlfhModFileTime.w; As Integer
zlfhModFileData.w; As Integer
zlfhCRC.l; As Long
zlfhCompressedSize.l; As Long
zlfhUncompressedSize.l; As Long
zlfhFileNameLength.w; As Integer
zlfhExtraFieldLength.w; As Integer
EndStructure
Procedure ListZipFile(Filename.s)
ReadHead.typZipLocalFileHead
FF=ReadFile(#PB_Any,Filename)
If FF
Repeat
ReadHead\zlfhSignature= ReadLong(ff)
If ReadHead\zlfhSignature=$4034B50
;Debug "valid Zip File!"
FileSeek(FF,Loc(ff)-4)
;Debug Loc(FF)
Laenge = ReadData(FF, @ReadHead, SizeOf(ReadHead))
;Debug Loc(FF)
With ReadHead
; Get the file name
If \zlfhFileNameLength<>0
FileString.s = Space(\zlfhFileNameLength)
;Debug Loc(FF)
Laenge = ReadData(FF, @FileString, \zlfhFileNameLength)
;Debug Loc(FF)
Debug Filestring
EndIf
Debug" Compressed=" + Str(\zlfhCompressedSize) + " UnCompressed=" + Str(\zlfhUnCompressedSize)
;Debug \zlfhExtraFieldLength
;Debug \zlfhBitFlag
; Work out how much extra Data To skip over
SeekSize = \zlfhCompressedSize
If \zlfhExtraFieldLength
SeekSize + \zlfhExtraFieldLength
EndIf
If (\zlfhBitFlag & $4)
SeekSize + 12
EndIf
;Debug Seeksize
EndWith
;Seek To Next record
Seeksize + Loc(FF)
;Debug Seeksize
FileSeek(FF,Seeksize)
; Increment file count
Filecount + 1
Else
If fileCount = 0
Debug "no valid ZIP"
EndIf
quitLoop = 1
EndIf
Until quitLoop
Debug Str(Filecount) + " in ZipFile"
CloseFile(FF)
EndIf
EndProcedure
FileName.s= "arrayClass.zip"
ListZipFile(FileName)
I may look like a mule, but I'm not a complete ass.