Function Reference


_WinAPI_FindFirstFileName

Creates an enumeration of all the hard links to the specified file

#include <WinAPIFiles.au3>
_WinAPI_FindFirstFileName ( $sFilePath, ByRef $sLink )

Parameters

$sFilePath The name of the file.
$sLink Returns the first link name found for the specified file.

Return Value

Success: The search handle.
Failure: 0 and sets the @error flag to non-zero, @extended flag may contain the system error code.

Remarks

After the search handle has been established, use it in the _WinAPI_FindNextFileName() function to search for other hard links to the specified file.

When the search handle is no longer needed, it should be closed using the _WinAPI_FindClose() function.

This function requires Windows Vista or later.

Related

_WinAPI_FindClose, _WinAPI_FindNextFileName

See Also

Search FindFirstFileNameW in MSDN Library.

Example

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

Local $sFile = @DesktopDir & '\@' & StringRegExpReplace(_WinAPI_PathFindFileName(@ScriptName), '\A_+', '')

; Create hard link to the current file with prefix "@" on your Desktop
If Not _WinAPI_CreateHardLink($sFile, @ScriptFullPath) Then
        MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), 'Error', 'Unable to create hard link.')
        Exit
EndIf

; Enumerate all hard links to the file

Local $sLink
Local $hSearch = _WinAPI_FindFirstFileName($sFile, $sLink)
While Not @error
        ConsoleWrite(_WinAPI_PathAppend(_WinAPI_PathStripToRoot($sFile), $sLink) & @CRLF)
        _WinAPI_FindNextFileName($hSearch, $sLink)
WEnd

Switch @extended
        Case 38 ; ERROR_HANDLE_EOF

        Case Else
                MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), @extended, _WinAPI_GetErrorMessage(@extended))
EndSwitch

FileDelete($sFile)