I would look at the parameters on which you DO want to delete, and work it something like this.
(Based on the following)
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Outlook';
$|++;
$Win32::OLE::Warn = 3; # Throw Errors, I'll catch them
my $OL = Win32::OLE->GetActiveObject('Outlook.Application')
|| Win32::OLE->new('Outlook.Application', 'Quit');
my $NameSpace = $OL->GetNameSpace("MAPI");
I used this to fill in some values:
my $Contacts = $NameSpace->Folders("Personal Folders")->Folders("Cont
+acts");
my @names = qw(Chuck Charles Charlie Chuckles);
foreach my $name (@names){
my $NewContact = $Contacts->Items->Add();
$NewContact->{FirstName}=$name;
$NewContact->{LastName}="Charbeneau";
$NewContact->Save();
print "Added $name\n";
}
And this to delete the names I don't like:
$Contacts = $NameSpace->Folders("Personal Folders")->Folders("Contact
+s")->{Items};
my $Cacharbes = $Contacts->Find("[LastName]=Charbeneau");
my $cnt = 0;
while (1) {
if ($Cacharbes->{FirstName} eq "Chuckles"){
$Cacharbes->Delete();
}
$Cacharbes = $Contacts->FindNext() || last;
}
The thing is, the find and find next function only return a single item from the main collection. Each item in a Contacts folder collection has a unique ->{EntryID} property, but it's not something you can remmber off the top of your head.
C-. |