-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
Quote:
>Hey,
>I'm working on a little project, and I need to read the names of the
>files in a zip file.
<snip>
Yes, no third party controls are needed.
My approach was to open the ZIP for binary input, and read the
Central Directory towards the end of the ZIP file. Below I am posting the
module containing the custom User Defined Types that I wrote after
studying the info from www.wotsit.org
The basic idea:
1)Scan the last 1024 bytes for the word: END_CD
This is "End Central Directory Header", then read
the last 18 bytes into udt *Public Type PKInit*
2) Compute the number of members of the Central Directory
from 1)
3)Backtrack 42 bytes per member got from 2)
4)Then your file properties are read into udt *Public Type
PKLocalFile*
5)Now you need to crunch out the VB Variant Date from a DOS date.
Have fun with the other properties, they are not too bad.
Best wishes,
Scripter's Object Browser, V 1.40
http://home.sprintmail.com/~mpryor/c-frame.htm?promo.htm
' begin fileformat.bas
Attribute VB_Name = "Module4"
Option Explicit
Public Const LFH_SIGNATURE = &H4034B50 'Before Data of each Member
Public Const CFH_SIGNATURE = &H2014B50 'For Each Member in Central
Directory
Public Const END_CD = &H6054B50 'End of Central Directory
'
' reference="http://www.wotsit.org"
' date="3/19/1999"
' author="Mark Pryor"
'
' Local file is a 42 byte structure found
' once for each file listed in the archive
'
Public Type PKLocalFile
nVersion As Integer 'Short
nVerToExtract As Integer 'Short
nGpbFlag As Integer 'Short
nCompMethod As Integer 'Short
nLastModTime As Integer
nLastModDate As Integer ' Needs bit blasting to
'extract the date string
dwCRC32 As Long
dwSizeComp As Long ' compressed size
dwSizeUnComp As Long ' uncompressed size
nCharsInFN As Integer 'Index to bFName
nExField As Integer 'Index to bExtraField
nFComLength As Integer 'Index to bFileComment
nDiskNumStart As Integer
nInAttributes As Integer
dwExAttributes As Long
dwOffsetLH As Long
End Type
Public bFName() As Byte
Public bExtraField() As Byte ' Usually dim 0
Public bFileComment() As Byte ' usually dim 0
'
' This is a structure found at the end of
' the zip file in last 18 bytes following END_CD
'
Public Type PKInit
nDisk As Integer 'Num of current disk
nDiskStartCenDir As Integer ' Disk where CD starts
nMemCDDisk As Integer 'Members of CD on cur disk
nTotalInCDCurDisk As Integer ' Should be equal to above
dwSizeCD As Long 'Bytes in CD
dwOffSetCurDisk As Long
nComLength As Integer 'normally zero
End Type
Public bComment() As Byte
Public Function Dos2VBDate(ByVal wint As Integer) As String
Dim l As Integer
Dim sTemp As String
'
' See Platform SDK:
' Automation/Conversion and Manipulation Functions
'
' Now get the years since 1980
'
l = wint And &HFE00 ' get bits 9 - 15
l = RShiftWord(l, 9) + 1980
sTemp = CStr(l)
'
' Get the Months 1-12
'
l = wint And &H1E0 ' get bits 5-8
' Now right shift 5 bits
l = RShiftWord(l, 5) 'get this from HCVB B. Mckinney
If l < 10 Then
sTemp = sTemp & "/" & "0" & CStr(l)
Else
sTemp = sTemp & "/" & CStr(l)
End If
'
' Get the days 1-31
'
l = wint And &H1F
If l < 10 Then
sTemp = sTemp & "/" & "0" & CStr(l)
Else
sTemp = sTemp & "/" & CStr(l)
End If
Dos2VBDate = sTemp
End Function
' end fileformat.bas
-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.3
iQA/AwUBOjb5r+qJdeoalm7FEQJvTgCgoRuHkNjbgoZ9PawgNHeXq/1Rl/AAn2S9
uRkK/MAM3rL9F1v/SbUktw1r
=dSC3
-----END PGP SIGNATURE-----