For those of you like myself, who are prone to shooting ones self in ones foot, I offer the following script that might allow you to escape the consequences of ones capricious actions! In less flowery verbiage, I recently came up with the brilliant idea of improving my development situation by pruning my perl development tree from the main perl trunk. Surely a sensible thing to do (
particularly since it shouldn't have been there in the first place) or at least so I thought until I noticed that all of my shortcuts (Windows
.lnk files) no longer worked. So here is a short piece of code that bailed me out and that might help fellow travelers as well.
#!/usr/bin/perl
# Fixlink.pl -- script to effect global change in link collection.
use strict;
use warnings;
use diagnostics;
use Win32::Shortcut;
edit_lnkpath( $_, qr/$ARGV[1]/, $ARGV[2] ) for map { glob } $ARGV[0];
sub edit_lnkpath {
my ( $file, $pat1, $pat2 ) = @_;
my $lnk = new Win32::Shortcut($file)
or die "Couldn't create shortcut object: $!";
my $path = $lnk->{'Path'};
if ( $path =~ /$pat1/ ) {
print "'$path' changed to ";
$path =~ s/$pat1/$pat2/;
print "'$path'\n";
$lnk->{'Path'} = $path;
$lnk->Save();
}
$lnk->Close();
}
--hsm
"Never try to teach a pig to sing...it wastes your time and it annoys the pig."