Solved

Number of files in a zip file

Posted on 2012-04-13
19
521 Views
Last Modified: 2012-08-14
I need code to find the total number of files in a zip file.

I am using Delphi XE.  Many thanks for your help.
0
Comment
Question by:rincewind666
  • 9
  • 9
19 Comments
 
LVL 4

Expert Comment

by:mvalencia2003
ID: 37843787
0
 

Author Comment

by:rincewind666
ID: 37844086
I am using XE, not XE2,

This doesn't contain TZipFile.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 37845516
You can use the Windows Shell object.
Example:
var
   objShell, ZipNS: Variant;

begin
   objShell := CreateOleObject('Shell.Application');
   ZipNS := objShell.Namespace('C:\Users\AikiMark\Downloads\CopyFromRecordset_Code_Dump.zip').Items( );
   ShowMessage(ZipNS.Count + ' files zipped up');

Open in new window

0
 

Author Comment

by:rincewind666
ID: 37846059
I am getting this error:

[DCC Error] Unit1.pas(46): E2003 Undeclared identifier: 'CreateOleObject'
0
 
LVL 45

Expert Comment

by:aikimark
ID: 37846205
you need to add ComObj to your Unit clause.
0
 

Author Comment

by:rincewind666
ID: 37846225
I am getting this error message:

Invalid number of parameters

Many thanks for your help.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 37846277
What does your code look like?
What statement is associated with the error?
0
 

Author Comment

by:rincewind666
ID: 37846476
procedure TForm1.Button1Click(Sender: TObject);
var
   objShell, ZipNS: Variant;

begin
   objShell := CreateOleObject('Shell.Application');
   ZipNS := objShell.Namespace('C:\Users\Chris\Desktop\98megpack.zip').Items( );
   ShowMessage(ZipNS.Count + ' files zipped up');
end;
0
 
LVL 45

Expert Comment

by:aikimark
ID: 37846872
1. what statement is failing?

2. remove the space between the parentheses after Items.
ZipNS := objShell.Namespace('C:\Users\Chris\Desktop\98megpack.zip').Items();

Open in new window

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:rincewind666
ID: 37846930
Removed the space but still the same error.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 37847013
what statement is producing the error?
0
 

Author Comment

by:rincewind666
ID: 37847901
I'm sorry. I don't know what you mean.  Here is the code:

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComObj;

type
  TForm2 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
var
   objShell, ZipNS: Variant;

begin
   objShell := CreateOleObject('Shell.Application');
   ZipNS := objShell.Namespace('C:\Users\Chris\Desktop\98megpack.zip').Items();
   ShowMessage(ZipNS.Count + ' files zipped up');

end;
end.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 37848326
There are three statements in your begin...end block.  Which one of the three is being executed when the error happens?
0
 
LVL 45

Expert Comment

by:aikimark
ID: 37848852
Please give this version a try.

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComObj;

type
  TForm2 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
var
   objShell, ZipNS, ZipItems: Variant;

begin
   objShell := CreateOleObject('Shell.Application');
   ZipNS := objShell.Namespace('C:\Users\Chris\Desktop\98megpack.zip');
   ZipItems := ZipNS.Items;
   ShowMessage(ZipItems.Count + ' files zipped up');

end;
end.

Open in new window

0
 

Author Comment

by:rincewind666
ID: 37849067
Sorry for the delay in replying.  I was called away from my computer.

I tried the new code but I get this message:

Could not convert variant of type (UnicodeString) into type (Double)
0
 
LVL 45

Expert Comment

by:aikimark
ID: 37849208
on what statement does this error occur?
0
 

Author Comment

by:rincewind666
ID: 37849230
ShowMessage(ZipItems.Count + ' files zipped up');
0
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
ID: 37849524
ShowMessage(IntToStr(ZipItems.Count) + ' files zipped up');

Open in new window

0
 

Author Closing Comment

by:rincewind666
ID: 37850168
Many thanks for your help aikimark.  Greatly appreciated.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now