Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Number of files in a zip file

Posted on 2012-04-13
19
Medium Priority
?
535 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
 

Author Comment

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

This doesn't contain TZipFile.
0
 
LVL 46

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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

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

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

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 46

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 46

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 46

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 46

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 46

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 46

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 46

Accepted Solution

by:
aikimark earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

688 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