Skip to main content

TrFile_ResolveAlias (function reference)

By June 1, 2024June 4th, 2024Online Help, Troi File Plug-in
Troi File Plug-in > Functions reference > TrFile_ResolveAlias
Troi File Plug-in for FileMaker Pro

TrFile_ResolveAlias

Resolves an alias file (or shortcut). It returns the path to the destination of the alias file.

SyntaxFunction badge

TrFile_ResolveAlias ( switches ; aliasPath )

Parameters

switches modifies the behavior of the function
aliasPath the path to the alias file

Switches

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

Returned Result

Data type returned

Text

Result

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.

Originated in

Troi File Plug-in 9.1

Compatibility

FileMaker Pro 17 to FileMaker Pro 21 (2024)

Considerations

On Windows an alias is called a shortcut and always has the extension .lnk.

Example

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”

Example 2

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).

Used in example file

FileManipulation.fmp12

Related functionFunction badge

TrFile_CreateAlias

Related script stepScript step badge

Create Alias

Related topics

Troi File Plug-in online help (overview)


Online Help Page for Troi File Plug-in for 17 to 2024 –> TrFile_ResolveAlias (filep4316) 2024-0604 19:28:28