Home: Project: Bookmark Converter
Code:
#!/user/ktsai/bin/perl
# Syntax: bmc <path/bookmarks.html>

sub populate ($$) {
  my $state = shift;
  my $spaces = shift;
  while (<>) {
    if ($state eq "nil") {
      if (/<DL>/) {$state = "start";}
    } elsif ($state eq "start") {
      if (/<\/DL>/) {
        chdir "..";
        last;
      } elsif (/<DT><A HREF=\"(http:\/\/.+?)\".*>(.+)<\/A>/) {    # a link
        $linkhttp = $1;
        $linkname = $2;
        $linkname =~ s/&amp[;]/&/;           # ampersands found in name
        open URL, ">$linkname.url";
        print URL "[DEFAULT]\n";
        print URL "BASEURL=$linkhttp\n\n";
        print URL "[InternetShortcut]\n";
        print URL "URL=$linkhttp\n\n";
        close URL;
      } elsif (/<DT><H\d.*>(.+)<\/H\d>/) {                 # a folder
        $foldername = $1;
        $foldername =~ s/^Personal Toolbar Folder/Links/;  # the bar
        print $spaces, "populate $foldername ...\n";
        rmdir $foldername;
        mkdir $foldername, 0700;
        chdir $foldername;
        $spaces .= "  ";
        populate ("nil", $spaces);
        chop($spaces);
        chop($spaces);
      }
    }
  }
}

print "NS to IE Bookmark Converter. Contact: [email protected]\n";
populate ("nil", "");
print "done.\n";

Example:
% cd ~/.microsoft/Favorites
% bmc ~/.netscape/bookmarks.html
NS to IE Bookmark Converter. Contact: [email protected]
populate Linux ...
  populate Download ...
  populate Distribution ...
    populate NASDAQ Listed ...
populate Windows ...
  populate Crack ...
    populate Reboot ...
      populate Hang ...
done.
%