I hope no one minds me sharing my source code, but I thought this script was
pretty cool. It allows you to modify an entire directory of html files. If you
check
and then look at
http://www.brie.com/~brian/bbd/
You will notice with the script I added a banner to the beginning of every page.
This is certainly a nice tool if you are managing a large site.
Get this, this script modified about two hundred files in about five seconds.
Here's my machines specs:
300 MHz AMD K6-2
128 Mb RAM
100 MHz Bus
Symbios UW SCSI
Quantum 3 Gig 5400rpm HD
#!/usr/bin/perl
# Configuration Variables
# Change these variables to match your web server's configuration
$base_dir = "/home/brian/public_html/bbd";
use File::Find;
finddepth(\&wanted, $base_dir);
sub wanted {
if (/\.html$/) {
$file = "$File::Find::name";
$old = "$file";
$new = "$file.tmp.$$";
$bak = "$file.bak";
open(OLD, "< $old") or die "can't open $old: $!";
open(NEW, "> $new") or die "can't open $new: $!";
# Correct typos, preserving case
while (<OLD>) {
if (/<BODY.*?>/) {
(print NEW $_) or die "can't write to $new: $!";
print NEW '<!-- replace navigable bar begin -->',"\n";
print NEW '<A HREF="/maps/brian.map">',"\n";
print NEW '<IMG SRC="/brian/pictures/bar.gif" WIDTH=551 HEIGHT=28 BORDER=0 ISMAP>',"\n";
print NEW '</A>',"\n";
print NEW '<!-- replace navigable bar end -->',"\n";
} else {
(print NEW $_) or die "can't write to $new: $!";
}
}
close(OLD) or die "can't close $old: $!";
close(NEW) or die "can't close $new: $!";
rename($old, $bak) or die "can't rename $old to $bak: $!";
rename($new, $old) or die "can't rename $new to $old: $!";
}
}
-- Brian Lavender http://www.brie.com/brian/ **************************************************************************** * To UNSUBSCRIBE from the list, send a message with "unsubscribe lug-nuts" * in the message body to majordomo@saclug.org. Please direct other * questions, comments, or problems to lug-nuts-owner@saclug.org.
This archive was generated by hypermail 2b29 : Fri Feb 25 2000 - 14:29:09 PST