Solved

Number of files in a zip file

Posted on 2012-04-13
19
522 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

896 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

15 Experts available now in Live!

Get 1:1 Help Now