ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA to expose details of zip files (https://www.excelbanter.com/excel-programming/351794-vba-expose-details-zip-files.html)

Chris Jones

VBA to expose details of zip files
 
I have a directory of zip files which I want to calculate the (gross) file
size of. Does anyone here know of a way to expose this information using VBA?

--
Chris Jones


Tom Ogilvy

VBA to expose details of zip files
 
Do you want the collective size of the zip files or the uncompressed size of
the files they contain?

What version of Windows?

--
Regards,
Tom Ogilvy


"Chris Jones" wrote in message
...
I have a directory of zip files which I want to calculate the (gross) file
size of. Does anyone here know of a way to expose this information using

VBA?

--
Chris Jones




Chris Jones

VBA to expose details of zip files
 
Tom,

I am after the total uncompressed size of the zip files contained in the
archive.
--
Chris Jones



"Tom Ogilvy" wrote:

Do you want the collective size of the zip files or the uncompressed size of
the files they contain?

What version of Windows?

--
Regards,
Tom Ogilvy


"Chris Jones" wrote in message
...
I have a directory of zip files which I want to calculate the (gross) file
size of. Does anyone here know of a way to expose this information using

VBA?

--
Chris Jones





Chris Jones

VBA to expose details of zip files
 
Sorry, I forgot to note that this is running Office 2003 on WindowsXP
Professional

--
Chris Jones



"Chris Jones" wrote:

Tom,

I am after the total uncompressed size of the zip files contained in the
archive.
--
Chris Jones



"Tom Ogilvy" wrote:

Do you want the collective size of the zip files or the uncompressed size of
the files they contain?

What version of Windows?

--
Regards,
Tom Ogilvy


"Chris Jones" wrote in message
...
I have a directory of zip files which I want to calculate the (gross) file
size of. Does anyone here know of a way to expose this information using

VBA?

--
Chris Jones





Tom Ogilvy

VBA to expose details of zip files
 
Put a new worksheet in the workbook and make it active

Then put this code in a new module in the workbook

Change the filename to point to your file:

Type FileHeader
signature As Long
version_made_by As Integer
version_needed As Integer
bitflags As Integer
comp_method As Integer
lastModFileTime As Integer
lastModFileDate As Integer
crc_32 As Long
comp_size As Long
uncompr_size As Long
fname_len As Integer
extra_field_len As Integer
fcomment_len As Integer
disk_num_start As Integer
internal_fattribute As Integer
external_fattribute As Long
relative_offset As Long
End Type
' char* file_name;
' char* extra_field;
' char* file_comment;


Sub GetDir()
'
' Tom Ogilvy
' 1/30/2006
'
Dim rw As Long
Dim j As Long, i As Long
Dim h As FileHeader
Dim c1 As Byte
Dim s As String, c As String
Dim fName as String

fName = "C:\MyFile.Zip"
Open fName For Binary As #1
rw = 1
i = 1
Do Until Loc(1) LOF(1)

Get 1, i, j
If j = 67324752 Then
ElseIf j = 33639248 Then
Get #1, i, h
ii = i + 46
s = ""
For k = 1 To h.fname_len
Get #1, ii, c1
s = s & Chr(c1)
ii = ii + 1
Next
Cells(rw, 1) = s
Cells(rw, 2) = h.comp_size
Cells(rw, 3) = h.uncompr_size
rw = rw + 1
End If
i = i + 1

Loop
Close #1
End Sub

--
Regards,
Tom Ogilvy


"Chris Jones" wrote in message
...
Sorry, I forgot to note that this is running Office 2003 on WindowsXP
Professional

--
Chris Jones



"Chris Jones" wrote:

Tom,

I am after the total uncompressed size of the zip files contained in the
archive.
--
Chris Jones



"Tom Ogilvy" wrote:

Do you want the collective size of the zip files or the uncompressed

size of
the files they contain?

What version of Windows?

--
Regards,
Tom Ogilvy


"Chris Jones" wrote in message
...
I have a directory of zip files which I want to calculate the

(gross) file
size of. Does anyone here know of a way to expose this information

using
VBA?

--
Chris Jones







Tim Williams

VBA to expose details of zip files
 
In addition to Tom's solution:

Sub Tester()
Dim sPath
Dim oApp As Object
Dim x As Integer
Dim o As Object


sPath = "U:\backup\Addin Backup 082503.zip"
Set oApp = CreateObject("Shell.Application")

For Each o In oApp.NameSpace(sPath).Items
Debug.Print o.Name & " ---- " & o.Size
Next o

Set oApp = Nothing

End Sub

--
Tim Williams
Palo Alto, CA


"Chris Jones" wrote in message
...
I have a directory of zip files which I want to calculate the (gross) file
size of. Does anyone here know of a way to expose this information using

VBA?

--
Chris Jones




Chris Jones

VBA to expose details of zip files
 
Tom,

I tried to run this against a couple of zip files I have and stepping
through the code, it never passed the test 'ElseIf j = 33639248 Then'.

In both zip files the value of j on the second get was 335807307 and not
33639248.
--
Chris Jones



"Tom Ogilvy" wrote:

Put a new worksheet in the workbook and make it active

Then put this code in a new module in the workbook

Change the filename to point to your file:

Type FileHeader
signature As Long
version_made_by As Integer
version_needed As Integer
bitflags As Integer
comp_method As Integer
lastModFileTime As Integer
lastModFileDate As Integer
crc_32 As Long
comp_size As Long
uncompr_size As Long
fname_len As Integer
extra_field_len As Integer
fcomment_len As Integer
disk_num_start As Integer
internal_fattribute As Integer
external_fattribute As Long
relative_offset As Long
End Type
' char* file_name;
' char* extra_field;
' char* file_comment;


Sub GetDir()
'
' Tom Ogilvy
' 1/30/2006
'
Dim rw As Long
Dim j As Long, i As Long
Dim h As FileHeader
Dim c1 As Byte
Dim s As String, c As String
Dim fName as String

fName = "C:\MyFile.Zip"
Open fName For Binary As #1
rw = 1
i = 1
Do Until Loc(1) LOF(1)

Get 1, i, j
If j = 67324752 Then
ElseIf j = 33639248 Then
Get #1, i, h
ii = i + 46
s = ""
For k = 1 To h.fname_len
Get #1, ii, c1
s = s & Chr(c1)
ii = ii + 1
Next
Cells(rw, 1) = s
Cells(rw, 2) = h.comp_size
Cells(rw, 3) = h.uncompr_size
rw = rw + 1
End If
i = i + 1

Loop
Close #1
End Sub

--
Regards,
Tom Ogilvy


"Chris Jones" wrote in message
...
Sorry, I forgot to note that this is running Office 2003 on WindowsXP
Professional

--
Chris Jones



"Chris Jones" wrote:

Tom,

I am after the total uncompressed size of the zip files contained in the
archive.
--
Chris Jones



"Tom Ogilvy" wrote:

Do you want the collective size of the zip files or the uncompressed

size of
the files they contain?

What version of Windows?

--
Regards,
Tom Ogilvy


"Chris Jones" wrote in message
...
I have a directory of zip files which I want to calculate the

(gross) file
size of. Does anyone here know of a way to expose this information

using
VBA?

--
Chris Jones








Tom Ogilvy

VBA to expose details of zip files
 
That is correct. It doesn't find it until much later in the file.
Stepping through it probably isn't what you want to do.

Look at Tim William's example which should work for Millenium and Windows
XP.

--
Regards,
Tom Ogilvy



"Chris Jones" wrote in message
...
Tom,

I tried to run this against a couple of zip files I have and stepping
through the code, it never passed the test 'ElseIf j = 33639248 Then'.

In both zip files the value of j on the second get was 335807307 and not
33639248.
--
Chris Jones



"Tom Ogilvy" wrote:

Put a new worksheet in the workbook and make it active

Then put this code in a new module in the workbook

Change the filename to point to your file:

Type FileHeader
signature As Long
version_made_by As Integer
version_needed As Integer
bitflags As Integer
comp_method As Integer
lastModFileTime As Integer
lastModFileDate As Integer
crc_32 As Long
comp_size As Long
uncompr_size As Long
fname_len As Integer
extra_field_len As Integer
fcomment_len As Integer
disk_num_start As Integer
internal_fattribute As Integer
external_fattribute As Long
relative_offset As Long
End Type
' char* file_name;
' char* extra_field;
' char* file_comment;


Sub GetDir()
'
' Tom Ogilvy
' 1/30/2006
'
Dim rw As Long
Dim j As Long, i As Long
Dim h As FileHeader
Dim c1 As Byte
Dim s As String, c As String
Dim fName as String

fName = "C:\MyFile.Zip"
Open fName For Binary As #1
rw = 1
i = 1
Do Until Loc(1) LOF(1)

Get 1, i, j
If j = 67324752 Then
ElseIf j = 33639248 Then
Get #1, i, h
ii = i + 46
s = ""
For k = 1 To h.fname_len
Get #1, ii, c1
s = s & Chr(c1)
ii = ii + 1
Next
Cells(rw, 1) = s
Cells(rw, 2) = h.comp_size
Cells(rw, 3) = h.uncompr_size
rw = rw + 1
End If
i = i + 1

Loop
Close #1
End Sub

--
Regards,
Tom Ogilvy


"Chris Jones" wrote in message
...
Sorry, I forgot to note that this is running Office 2003 on WindowsXP
Professional

--
Chris Jones



"Chris Jones" wrote:

Tom,

I am after the total uncompressed size of the zip files contained in

the
archive.
--
Chris Jones



"Tom Ogilvy" wrote:

Do you want the collective size of the zip files or the

uncompressed
size of
the files they contain?

What version of Windows?

--
Regards,
Tom Ogilvy


"Chris Jones" wrote in

message
...
I have a directory of zip files which I want to calculate the

(gross) file
size of. Does anyone here know of a way to expose this

information
using
VBA?

--
Chris Jones











All times are GMT +1. The time now is 07:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com