2

After switching from Windows to Linux, I am left with a favourite directory containing subfolders and .url files, each file containing a few lines of text that look like this:

[DEFAULT]
BASEURL=http://www.example.com/faq.html
[InternetShortcut]
URL=http://www.example.com/faq.html
Modified=70E5E788C3B9C9010A

Since I do not have internet explorer installed on my Linux system, it is not possible for me to import the bookmarks directly to my current Firefox browser.

I was wondering if there is a quick way to extract the URL from all the .url files, together with the filenames to generate a .htm file which I can import to any modern browser.

Pierre.Vriens
  • 1,088
  • 21
  • 13
  • 16
Question Overflow
  • 4,568
  • 19
  • 57
  • 84

1 Answers1

3

You can do this with a little perl:

#!/usr/bin/perl
use strict;
use warnings qw(all);

use HTML::Entities qw(encode_entities);
use Config::IniFiles;
use File::Spec;

foreach my $f (@ARGV) {
    my $ini = Config::IniFiles->new( -file => $f );
    my (undef, undef, $name) = File::Spec->splitpath($f);
    $name =~ s/\.url$//;            # / # this comment un-confuses the syntax highlighter
    my $name_esc = encode_entities($name);
    my $url_esc = encode_entities($ini->val('InternetShortcut', 'URL'));
    print <<HTML
<a href="$url_esc">$name_esc</a>
HTML
}

That should handle everything well. You chould use grep & cut, but then you'd have to hope escaping isn't required, and that the sections in the ini-format .url file don't matter.

derobert
  • 107,579
  • 20
  • 231
  • 279
  • Thanks for this nice solution. I spent half a day crash course on perl and finally got this to work. For those uninitiated, first you need to install gcc compiler, then the two modules `HTML::ENtities` and `Config::IniFiles`. The path to these modules may be in root, and may require `use lib`. And `@ARGV` contains the input of file paths. – Question Overflow Apr 17 '13 at 07:44
  • @QuestionOverflow Not sure which distro you're running, but I'm surprised there weren't packages for those two modules. But I fully encourage learning at least a little Perl (or Ruby, or Python), they can quickly solve all sorts of problems like this. – derobert Apr 17 '13 at 14:36