Umlaut has asked for the wisdom of the Perl Monks concerning the following question:

Hi there,
I need to be able to create hard links via Perl on Win2000. Naturally I'm using an NTFS partition ('D:') and let's assume I have a file "something.txt" in a folder called "folder". The following code was converted from another (evil) COM scripting language. However, it does not succeed.
use Win32::OLE('in'); my $class = "HardLink.Object.1"; my $hardlink = new Win32::OLE($class); my $sNewFile = "D:\folder\somefile.txt"; my $sExistingFile = "D:\somefile.txt"; my $Result = $hardlink->CreateNewHardLink($sNewFile, $sExistingFile);

$hardlink does not resolve as an object (so you get an error trying to call a method on it). Does anyone know what's wrong or have another way? Thanks!

Replies are listed 'Best First'.
(tye)Re: Creating Hard links in Win2000?
by tye (Sage) on Apr 20, 2001 at 09:48 UTC

    For recent versions of Perl, I believe this can be done much more simply (and even portably) using...

    link

            - tye (but my friends call me "Tye")
Re: Creating Hard links in Win2000?
by japhy (Canon) on Apr 20, 2001 at 06:14 UTC
    Upon checking Win32::OLE->LastError, I see that "HardLink.Object.1" is an invalid class name. Shucks.

    japhy -- Perl and Regex Hacker
Re: Creating Hard links in Win2000?
by premchai21 (Curate) on Apr 20, 2001 at 06:06 UTC
    I'm not sure that it actually has anything to do with Win32::OLE. Notice that your strings are in double quotes. This means that, for instance, $sNewFile eq 'D:~older~omefile.txt' where the ~s represent strange unprintable characters. Use single quotes, forward slashes, or double backslashes.