Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Grab all IE bookmarks on a windows machine.

by jryan (Vicar)
on Nov 26, 2001 at 00:09 UTC ( #127411=CUFP: print w/replies, xml ) Need Help??

I went home for Thanksgiving this weekend, and while I was there, I wanted to grab a bunch of old bookmarks on my old computer, and then send the urls to myself back at college. However, IE doesn't have an "export bookmarks" feature. So, I wrote a quick one-off CGI script to go through the bookmarks folder and grab the urls from the files, and then spit them out in plain text format.
#!perl -w use strict; use CGI qw(header); use File::Find; print header(-type=>"text/plain"); find(\&wanted, $ENV{USERPROFILE}); sub wanted { stat $File::Find::name; return if -d; return unless -r && -f; open (BOOKMARK, $File::Find::name); my @bookmark=<BOOKMARK>; close (BOOKMARK); my $head; if ($bookmark[1] =~ /^BASEURL=/){$head=8} else{$head=4} print substr($bookmark[1],$head,length($bookmark[1])); }
Update: Added $ENV{USERPROFILE} instead of hardcoded path thanks to a comment by $code or die.

Replies are listed 'Best First'.
Re: Grab all IE bookmarks on a windows machine.
by Fastolfe (Vicar) on Nov 26, 2001 at 06:28 UTC

    A more robust solution might be to parse the .URL file itself (it's a standard Windows INI file) and pull out the attribute you need. Granted, your script may work 100% of the time today, it's only doing so because you're making some big assumptions.

    Also, I suspect the 'BASEURI' attribute might actually be usable in a way... It sounds like a base from which to resolve a relative 'URL', though I haven't found any shortcuts that store their URL's in a relative fashion, so I dunno. Couldn't hurt to put it in there Just In Case, though...

    sub wanted { return unless -f && -r; if (/\.url$/i) { my $ini = new Config::Ini $_; my $base = $ini->get(['DEFAULT', 'BASEURL']); my $url = $ini->get(['InternetShortcut', 'URL']); my $uri = $base ? URI->new_abs($url, $base) : URI->new($url); print $uri->as_string, "\n"; # or whatever } }
      Hm, wouldn't you want to match upper-case names as well, e.g. /\.url$/i ?

          -- Chip Salzenberg, Free-Floating Agent of Chaos

        Yah I guess...
Re: Grab all IE bookmarks on a windows machine.
by $code or die (Deacon) on Nov 26, 2001 at 18:10 UTC
    Grab all IE bookmarks on a windows machine
    That's not strictly true. Your script will work on most Win9x or WinMe machines. On WinNT and Win2k, you'll want to search these other folders (unless you have moved the folders or installed on a different drive):

    WinNT: c:/winnt/profiles/[username]/favorites
    Win2k: c:/Documents and Settings/[username]/favorites

    To get the logged in user's profile folder, use $ENV{USERPROFILE}.

    Simon Flack ($code or die)
    $,=reverse'"ro_';s,$,\$,;s,$,lc ref sub{},e;$,
    =~y'_"' ';eval"die";print $_,lc substr$@,0,3;
Re: Grab all IE bookmarks on a windows machine.
by belg4mit (Prior) on Nov 26, 2001 at 07:35 UTC
    Well unless you switched to Netscape (why not?) there's no reason to even do any kind of parsing, just copy all of the shortcuts onto a floppy (or zip them up and mail them). Why CGI?

    UPDATE: Something like this might have been useful too.

    perl -p -e "s/(?:\w);([st])/'\$1/mg"

      Its because I use Mozilla at college, and my parents use IE at home.
Re: Grab all IE bookmarks on a windows machine.
by Anonymous Monk on Dec 12, 2001 at 20:52 UTC
    I've been playing a while with similar things, including programs to (a) scan a local copy of a website for various things, (b) manipulate windows' favourites, and (c) auto-index directories as HTML.
Re: Grab all IE bookmarks on a windows machine.
by Spudnuts (Pilgrim) on Dec 12, 2001 at 00:25 UTC
    IE 5.5 has a bookmark export tool. File-> Import/Export-> Export Bookmarks.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://127411]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2022-06-30 15:57 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (98 votes). Check out past polls.