in reply to How to create symlink using Perl?

Windows NTFS supports Junctions which are very similar to Unix symlinks (see also Sysinternals Junction).

Update: unlike Unix symlinks, be aware that Windows junctions are for directories only (see Re^5: How to create symlink using Perl? and Win32::Symlink for more detail).

I've successfully used the CPAN Win32::Symlink module by audreyt (in particular, it's symlink function) to write cross-platform code that used "symlinks" on both Unix and Windows. At the top of the program, I used:

BEGIN { if ($^O eq 'MSWin32') { require Win32::Symlink; Win32::Symlink->import(); } }

The rest of the code (using the symlink function) was the same for both platforms.

Replies are listed 'Best First'.
Re^2: How to create symlink using Perl?
by ikegami (Patriarch) on Oct 23, 2011 at 09:26 UTC
    By the way, that can be written as
    use if $^O eq 'MSWin32', 'Win32::Symlink';

      This module is reported to be broken in current versions of activestate perl:  http://code.activestate.com/ppm/Win32-Symlink/  http://matrix.cpantesters.org/?dist=Win32-Symlink+0.04

      Am using activestate Perl version 5.12.3.1204 and windows 7 32bit with NTFS. How to shell out to mklink?

        I tried with active perl version 5.8.8 and the Win32::Symlink module got installed. But it created only directory juntion despite passing a file.

        @Corion Thanks for the suggestion. Now I am able to run the mklink command of windows directly inside in perl script and able to create the desired symbolic links.
        my $oldfilename = File::Spec->catfile($oldname); my $newfilename = File::Spec->catfile($newname); if(-f $newfilename){ } else { @args = ("mklink", $newfilename, $oldfilename); system(@args) == 0; }
Re^2: How to create symlink using Perl?
by freonpsandoz (Beadle) on Oct 08, 2016 at 22:36 UTC

    Junctions are symbolic links to directories, not to files. I cannot get Win32::Symlink::symlink to create a symbolic link to a file. It also seems to work only for directories, although I can't find any documentation of this limitation.