Resolves an alias file (or shortcut). It returns the path to the destination of the alias file.
TrFile_ResolveAlias ( switches ; aliasPath )
|switches||modifies the behavior of the function|
|aliasPath||the path to the alias file|
Switches can be empty or you can add this switch:
|-ReturnLastKnownPath||if the alias is broken this will return the last path the alias pointed to|
Data type returned
The returned result is the path to the destination of the alias file or an error code. An error always starts with 2 dollars, followed by the error code. You should always check for errors. Returned error codes can be:
|$$-43||fnfErr||the alias file was not found|
|$$-4286||kErrCantResolveAlias||the alias is broken, possibly because the destination no longer exists|
|$$-4287||kErrInvalidAliasFile||the alias file is not correct, or not an alias at all|
|$$-1302||notAFileErr||a directory was specified (which can’t be an alias)|
Other errors may be returned.
Troi File Plug-in 9.1
FileMaker Pro 14 to 18
On Windows an alias is called a shortcut and always has the extension .lnk.
Set Field [ $ErrorCode ; TrFile_ResolveAlias ( "-Unused" ; "Mac HD:kip:salad alias" ) ]
This will try to resolve the alias and returns the path to the destination, for example MacHD:Users:john:Documents:salad.txt”
We assume that in your FileMaker file the following fields are defined:
this::TheFilePath the path to the alias, for example "MacHD:Users:Amy:Desktop:AliasFile" this::ResolveStatus text this::DestFileSpec text this::gErrorCode text
This example will first set the variable from the path stored in the field this::TheFilePath and then resolve the alias. In a script add the following steps:
# Store the (alias) path in a variable first: Set Variable [ $TheFileSpec ; this::TheFilePath ] # Resolve the alias now: Set Variable [ $ResultPath ; TrFile_ResolveAlias ( "" ; $TheFileSpec ) ] # Get the error code: Set Variable [ $ErrorCode ; If ( Left ( $ResultPath ; 2 ) <> "$$" ; 0 ; $ResultPath ) ] If [ $ErrorCode = 0 // the alias was resolved ] Set Variable [ $ResolveStatus ; "The alias was resolved." ] Else If [ $ErrorCode = "$$-4287" ] # The alias file is not correct, or not an alias file at all. Set Variable [ $ResolveStatus ; "The alias file is invalid or not an alias file." ] Set Variable [ $ResultPath ; "" ] Else If [ $ErrorCode = "$$-4286" // can't resolve the alias ] #The alias is broken, possibly because the destination no longer exists. #We now try if we can get the last known path from the alias: Set Variable [ $ResultPath ; TrFile_ResolveAlias ( "-ReturnLastKnownPath" ; $TheFileSpec ) ] # Get the error code: Set Variable [ $ErrorCode ; If ( Left ( $ResultPath ; 2 ) <> "$$" ; 0 ; $ResultPath ) ] Set Variable [ $ResolveStatus ; If ( $ErrorCode = 0 ; "Alias is broken, last known path stored." ; "An error occurred resolving the alias." ) ] Else Set Variable [ $ResolveStatus ; "An unknown error occurred. Error code = " & $ErrorCode ] End If #Save the result and error code into fields: Set Field [ this::ResolveStatus ; $ResolveStatus ] Set Field [ this::DestFileSpec ; $ResultPath ] Set Field [ this::gErrorCode ; $ErrorCode ] # Return the resulting error code: Exit Script [ $ErrorCode ]
This script will try to resolve the alias. If it succeeds the destination will be returned. If the alias is broken it will try to return the last known path of the destination (before the alias was broken).
Related script step