#!/usr/local/perl -s

# remove empty html files
use strict;
use File::Find;

our $v;     # command lne option

my $pattern = q {<!-- INDEX END -->

<table border="0" width="100%" cellspacing="0" cellpadding="3">
<tr><td class="block" style="background-color: #cccccc" valign="middle">
};

die "Usage: $0 directoryname\n" unless @ARGV;

find(\&wanted, @ARGV);
exit 0;

sub wanted
{
    return if (-d $_);  # ignore directories
    my $f = $File::Find::name;
    #print "file = $f\n";
    my $fh;
    open($fh, "<$f") || die $!;

    local $/ = undef;
    $_ = <$fh>;
    close $fh;
    if ( /\Q$pattern\E/s ) {
        print "EMPTY file = $f\n" if $v;
        chmod 0755, $f;
        unlink $f;
    }
}

