Function Reference

首页  后退  前进

FileCreateNTFSLink

 

创建 NTFS 硬连接到文件或目录

 

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

参数

source

创建硬链接的源路径.

hardlink

硬链接的路径.

flag

[可选] 是否覆盖已存在的链接.

可以是以下值的组合:

   $FC_NOOVERWRITE (0) = (默认) 不覆盖已存在的链接

   $FC_OVERWRITE (1) = 覆盖存在的链接

 

常量定义在 FileConstants.au3

返回值

成功:

返回 1.

失败:

返回 0.

备注

目标目录必须已经存在.

 

函数仅工作于 NTFS 文件系统.

 

如果源路径是一个文件,硬连接必须在同一卷.

如果源路径是一个目录,硬连接可以不在同一卷.

 

FileDelete()FileMove() 可以用于硬连接.

 

要管理与资源管理器的链接,可以使用 shell 扩展 NTFSLink

相关

FileCreateShortcut

函数示例

#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, @DesktopDir & "\ExampleNTFSLink.log")
    ; Display a message of whether the NTFS link was created.
    If $iNTFSLink Then
        ; Open the desktop directory.
        ShellExecute(@DesktopDir)
        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(@DesktopDir & "\ExampleNTFSLink.log")
EndFunc   ;==>Example

----------------------------------------