Solved

Number of files in a zip file

Posted on 2012-04-13
19
531 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 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