Function Reference


FileCreateNTFSLink

Creates an NTFS hardlink to a file or a directory.

FileCreateNTFSLink ( "source", "hardlink" [, flag = 0] )

Parameters

source Path of the source to which the hardlink will be created.
hardlink Path of the hardlink.
flag [optional] this flag determines whether to overwrite link if they already exist.
Can be a combination of the following:
    $FC_NOOVERWRITE (0) = (default) do not overwrite existing link
    $FC_OVERWRITE (1) = overwrite existing link

Constants are defined in FileConstants.au3.

Return Value

Success: 1.
Failure: 0.

Remarks

The destination directory must already exist.

This function works only on volumes with the NTFS File system.

If the source is a file, the hardlink must be on the same volume.
If the source is a directory cross volume is allowed.

FileDelete() or FileMove() can be used on hardlink.

To manage the link with the explorer you can use the shell extension NTFSLink

Related

FileCreateShortcut

Example

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

Example()

Func Example()
        ; Create a constant variable in Local scope of the filepath that will be read/written to.
        Local Const $sFilePath = _WinAPI_GetTempFileName(@TempDir)

        ; Create a temporary file to link to.
        If Not FileWrite($sFilePath, "This is an example of using FileCreateNTFSLink.") Then
                MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
                Return False
        EndIf

        ; Create a NTFS link of the .txt file to the .log file on the desktop.
        Local $iNTFSLink = FileCreateNTFSLink($sFilePath, @TempDir & "\ExampleNTFSLink.log")

        ; Display a message of whether the NTFS link was created.
        If $iNTFSLink Then
                ; Open the desktop directory.
                ShellExecute(@TempDir)

                MsgBox($MB_SYSTEMMODAL, "", "The NTFS link was created." & @CRLF & "FileCreateNTFSLink returned: " & $iNTFSLink)
        Else
                MsgBox($MB_SYSTEMMODAL, "", "The NTFS link wasn't created." & @CRLF & "FileCreateNTFSLink returned: " & $iNTFSLink)
        EndIf

        ; Delete the temporary files.
        FileDelete($sFilePath)
        FileDelete(@TempDir & "\ExampleNTFSLink.log")
EndFunc   ;==>Example