Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How to create symlink using Perl? (Unix symlinks vs Windows Junctions)

by eyepopslikeamosquito (Archbishop)
on Oct 23, 2011 at 09:02 UTC ( [id://933177]=note: print w/replies, xml ) Need Help??


in reply to How to create symlink using Perl?

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

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.

Update: Re^5: How to create symlink using Perl? advises using Win32::Symlink for directories only, not files (because Windows junctions are for directories only)

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://933177]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-19 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found