Perl Kung-Fu: How to Setup an IE-Inbox

by phil on Saturday Mar 20, 2004 1:04 PM

There is a magical folder on my Windows desktop where I can click-and-drag URL shortcuts directly into Philosophistry (this appears in the right-quadrant of my blog). I can also kill links just as easily as I create them, by dragging them away into the recycle bin. In other words, part of my site is a real-time portal into a directory on my computer.

For the curious, here's the way I did it.

First, I have server-side includes enabled on my site, which allows scripts to be executed from my HTML before they reach visitors.

So in the source code of my index.shtml, it says:

<!--#exec cmd="ie_inbox.pl"-->

If you tried to "View Source" you would not see that line as the server strips it out before its served. This is called "pre-processing."

That line executes the following Perl script.

#!perl

$dir = "/Documents and Settings/Philip Dhingra/Desktop/ie_inbox/";

opendir(DIR, $dir);
@files = readdir(DIR);

sort (@files);

foreach $file (@files) {
	if (-f "$dir$file" && $file =~ /\.url$/i) {
		open URL, "$dir$file";
		while () {
			if (/^URL=/) {
				chomp;
				$_ =~ s/^URL=//;
				$file =~ s/\.URL$//i;
				print "<li><A TARGET=_blank HREF=\"$_\">$file</A>\n";
				close URL;
				break;
			}
		}
	}
}

(You may use this just sorta give credit where credit is due)

In a nutshell, the script searches for all the .url files in a specified folder, opens them up, and then rips out the URL string. It then uses the name of the file as the title of the site and then kicks out a hyperlink. Easy as that.
Creative Commons License