• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 540
  • Last Modified:

Number of files in a zip file

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
rincewind666
Asked:
rincewind666
  • 9
  • 9
1 Solution
 
mvalencia2003Commented:
0
 
rincewind666Author Commented:
I am using XE, not XE2,

This doesn't contain TZipFile.
0
 
aikimarkCommented:
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
rincewind666Author Commented:
I am getting this error:

[DCC Error] Unit1.pas(46): E2003 Undeclared identifier: 'CreateOleObject'
0
 
aikimarkCommented:
you need to add ComObj to your Unit clause.
0
 
rincewind666Author Commented:
I am getting this error message:

Invalid number of parameters

Many thanks for your help.
0
 
aikimarkCommented:
What does your code look like?
What statement is associated with the error?
0
 
rincewind666Author Commented:
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
 
aikimarkCommented:
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
 
rincewind666Author Commented:
Removed the space but still the same error.
0
 
aikimarkCommented:
what statement is producing the error?
0
 
rincewind666Author Commented:
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
 
aikimarkCommented:
There are three statements in your begin...end block.  Which one of the three is being executed when the error happens?
0
 
aikimarkCommented:
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
 
rincewind666Author Commented:
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
 
aikimarkCommented:
on what statement does this error occur?
0
 
rincewind666Author Commented:
ShowMessage(ZipItems.Count + ' files zipped up');
0
 
aikimarkCommented:
ShowMessage(IntToStr(ZipItems.Count) + ' files zipped up');

Open in new window

0
 
rincewind666Author Commented:
Many thanks for your help aikimark.  Greatly appreciated.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 9
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now