Re: Conversion of Favorite (MSIE) to Bookmark (Netscape-Linux)



On Fri, Aug 04, 2000 at 12:04:47PM +0800, Stephen Liu wrote:

> Kindly advise how to convert Favorite (MS InternetExplorer) to
> Bookmark (Netscape-Linux).

This is a bit off-topic for gnome-list, but in the interest of helping
someone transition away from MSIE, I've attached the following bit of
Perl code that I've used to perform this conversion.  It walks an MS
favorites-style directory tree, writing out the equivalent HTML, which
is what Netscape uses to store its bookmarks, as it goes.  If you
don't have Perl on your MS box, just zip up your "favorites" directory
tree, move this to a Unix box, and do the conversion there.

I haven't tried using this with any recent version of Netscape, so the
output format may need a bit of tweeking.  Best of luck.

-- John Kodis.

#!/usr/bin/perl -w
#
# fav2html -- converts MS favorites tree to Netscape style bookmarks file.
# Usage: fav2html favorites >bookmarks.html
#
use strict;
use Cwd;

sub url {
    my ($fn) = @_;
    my $title = $fn;
    $title =~ s/.url$//i;
    open URL, $fn or die "can't open $fn";
    my @url = grep s/^URL=//, <URL>;
    $url[0] =~ s/\s+$//;
    close URL;
    printf "<dt><a href=$url[0]>$title</a>\n";
}

sub dir_top {
    my ($fn) = @_;
    printf "<dt><h3>$fn</h3><dd><dl><p>\n";
}

sub dir_bot {
    my ($fn) = @_;
    printf "</dl><p>\n";
}

sub url2html {
    my @args = @_;
    my $fn;
    foreach $fn (@args) {
	if (-f $fn and $fn =~ /\.url/i) {
	    url($fn);
	} elsif (-d $fn) {
	    dir_top($fn);
	    chdir $fn or die "can't cd to $fn\n";
	    opendir DIR, "." or die "can't open directory $fn";
	    url2html(grep !/^\./, readdir DIR);
	    closedir DIR;
	    chdir ".." or die "can't cd up from $fn\n";
	    dir_bot($fn);
	}
    }
}

exit !url2html(@ARGV);





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]