Reading files from a zip file (Just reading the filenames, not unzipping or zipping) 
Author Message
 Reading files from a zip file (Just reading the filenames, not unzipping or zipping)

Hey,

I'm working on a little project, and I need to read the names of the files
in a zip file.

For example MyZip.zip
en I need to get

file1.exe
file2.txt
file3.txt

Can I do this without using 3rd party controls ?

THNX :-)



Sat, 31 May 2003 20:09:23 GMT  
 Reading files from a zip file (Just reading the filenames, not unzipping or zipping)
-----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-----



Sun, 01 Jun 2003 12:26:34 GMT  
 Reading files from a zip file (Just reading the filenames, not unzipping or zipping)
THNX :-)))
I'll have a look at this right away :-)


-----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-----



Sun, 01 Jun 2003 14:57:54 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. VB3 Binary FILES READ READ READ

2. Reading Data From An Excel File - source.zip (0/1)

3. Question: How do I read a .zip file with VB4

4. problem with reading zip files

5. control to read à ZIP file ?

6. Zipping and Unzipping files

7. Unzip automatically the attachments zip files

8. how to unzip .zip files?

9. zipping/unzipping files from VB Code.

10. Database Controls with Filenames read from .INI file?

11. Zipping\Unzipping files

12. zip/unzip files

 

 
Powered by phpBB® Forum Software