Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Grab all IE bookmarks on a windows machine.

by jryan (Vicar)
on Nov 26, 2001 at 00:09 UTC ( [id://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 Spudnuts (Pilgrim) on Dec 12, 2001 at 00:25 UTC
    IE 5.5 has a bookmark export tool. File-> Import/Export-> Export Bookmarks.
Re: Grab all IE bookmarks on a windows machine.
by Anonymous Monk on Dec 12, 2001 at 20:52 UTC
    Site
    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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-03-28 19:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found