The function returns the path to the file / folder pointed to by a Symbolic link or Junction Point.
1 2 3 4 5 6 7 8 9 |
var path: string; linkTarget: string; begin path:= 'C:\Documents and Settings'; linkTarget:= SymLinkTarget(path); ShowMessage(linkTarget); end; |
Options
path - path to a symbolic link or junction point
Result
The path to the target of a symbolic link or junction point.
If the object is not a reference, the path to it will be returned.
If the object is not found, the system message is: System error. Code: 2. The specified file cannot be found.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
function SymLinkTarget(path: string): string; var LinkHandle: THandle; TargetName: array [0..512] of Char; begin LinkHandle := CreateFile(PChar(path), 0, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0); Win32Check(LinkHandle <> INVALID_HANDLE_VALUE); try if GetFinalPathNameByHandle(LinkHandle, TargetName, 512, FILE_NAME_NORMALIZED) > 0 then Result:= Copy(TargetName, 5, maxint) // TargetName получаем в виде UNC пути (\\?\C:\Users\...) else RaiseLastOSError; finally CloseHandle(LinkHandle); end; end; |