Solved

Number of files in a zip file

Posted on 2012-04-13
19
524 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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 Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

803 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