#! /usr/local/bin/perl -w # # killVCF # # written by Vicki Brown # # save as a MacPerl runtime or droplet # # Delete VCard files in Eudora Attachments folder # Default folder is "System Folder:Eudora Folder:Attachments Folder" # or you can drop a folder, or change this default, or the script will prompt # # 1 2 3 4 5 6 7 8 9 #23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 # # "Global" variables # use strict 'refs'; no strict 'subs'; no strict 'vars'; use File::Copy; use File::Basename; use Mac::Files; use Mac::StandardFile; # # Global "constants" # # $RCSID = '$Id$'; # uncomment if used # defined locally use vars qw($DEBUG $PROG $USAGE); use vars qw($verbose $warnings); $DEBUG=0; # set to > 0 for debugging levels; set to 0 to turn off $PROG = basename($0); $USAGE = "Usage: $PROG AttachmentsFolder"; $verbose = 1; # print stuff to the screen if ($verbose) $warnings = 0; # warn and continue on certain errors instead of dying; see oops() # # Global variables # use vars qw($sysfile $eudorafldr $attachdir); $sysfile = FindFolder(kOnSystemDisk, kSystemFolderType); $eudorafldr = "$sysfile:Eudora Folder"; $attachdir = "$sysfile:Eudora Folder:Attachments Folder"; # As installed $attachdir = "$sysfile:Eudora Folder:Attachments"; # localized $attachdir="Ask User to Choose"; # # Main # { # general setup... my $vcf_cnt = 0; # count number of Vcards found if (@ARGV > 0) { $attachdir = shift; # drop a folder to override default # } else { # use default from above; if not found, script will prompt } # Open input directory if (-d "$attachdir") { # it exists (dropped or hardwired) and is a directory opendir(INDIR, "$attachdir") || die "Oops, canot open $attachdir!\n"; } elsif (-e "$attachdir") { # it exists but is not a directory die "$attachdir is not a folder!\n"; } else { # ask the user $attachdir = get_folder( "Choose a folder to grovel.", $eudorafldr ); if (-e "$attachdir") { opendir(INDIR, "$attachdir") || die "Oops, canot open $attachdir!\n"; } else { die "Cannot open $attachdir!\n"; } } print "Attachments are in $attachdir\n" if ($verbose); # loop over the list of files in the directory # while ($name = readdir(INDIR)) { @files = readdir(INDIR); close(INDIR); foreach $name (sort @files) { # Do stuff if ($name =~ /\.vcf$|\.vcf \d/) { $vcf_cnt++; print "$name\n" if ($verbose); unlink("$attachdir:$name"); } } # while ($name = readdir(INDIR)) closedir(INDIR); print "Found $vcf_cnt VCards.\n" if ($verbose); exit(0); } # main block sub get_folder { my($prompt, $default) = @_; my $nav = eval {require Mac::Navigation}; $default = '' unless defined($default); if ($nav) { my($opt, $fold, $file); Mac::Navigation->import(); $opt = NavGetDefaultDialogOptions(); $opt->message($prompt); $fold = NavChooseFolder($default, $opt) or die $^E; $file = $fold->file(1); $file =~ s/:$//; $file; } else { require 'GUSI.ph'; MacPerl::Choose( GUSI::AF_FILE(), 0, $prompt, '', GUSI::CHOOSE_DIR() + ($default ? GUSI::CHOOSE_DEFAULT() : 0), $default ); } } sub usage { # # print a usage message and die my($message) = @_; print STDERR ("$0: $message") if defined($message); die("$USAGE\n"); } # sub usage