Subscribe#!/usr/bin/perl -w
use strict;
use File::Find;
use File::Spec::Functions qw/rel2abs :DEFAULT/;
use HTML::TreeBuilder;
if (@ARGV != 2) {
print STDERR "usage: ./html-rename <in dir> <out dir>\n";
exit 1;
}
my $in = rel2abs( shift );
my $out = rel2abs( shift );
find( \&wanted, $in );
sub wanted {
my ($fname, $tree, $title, $count);
return unless /\.htm(l)?$/;
$tree = HTML::TreeBuilder->new_from_file( $_ );
if ($title = $tree->look_down( '_tag', 'title' )) {
$fname = $title->as_text . '.html';
$fname =~ s/[\|&`\$\*\?~]//g;
} else {
$fname = $_;
}
if (-e catfile( $out, $fname )) {
print STDERR "DUPLICATE: $fname\n";
return;
}
link $_, catfile( $out, $fname );
$tree->delete;
}
You are not logged in, either login or create an account to post comments
posted by charmston at 10:18 PM on February 13, 2006