How can Perl see where a Windows shortcut points to?

Viewed 45

In Windows, how can I check where a shortcut file points to? In the following simple code, readlink doesn't show anything:

$dir = 's:\\aaaaa\\bbb';
.....
@img = readdir F;
@lnk = grep{/lnk$/} @img;
......
......

foreach (@lnk){
    $where = readlink $dir.$_;
    $a=$a;
}
1 Answers

According to perlport, readlink is not implemented on Windows. Instead you can use Win32::Shortcut to read shortcut .lnk files:

use strict;
use warnings;
use feature qw(say);
use Win32::Shortcut;
my $link = Win32::Shortcut->new();
$link->Load("test.lnk");
say "Shortcut to: $link->{'Path'} $link->{'Arguments'}";
$link->Close();
Related