Returns the path to an object, at the moment the path to the FileMaker application or the current FileMaker file.
TrFile_GetPathTo ( switches ; desiredFilename ; fileSize )
|switches||this determines which path is returned|
|desiredFilename||the name of the file to find|
|fileSize||the size of the file to find|
switch can be one of the following:
|-CurrentApplication||return the FileSpec of the FileMaker application|
|-CurrentFileName||return the FileSpec of the FileMaker file that is currently active (the front window)|
|-CurrentAppFolder||return the folder of the current running (FileMaker) application|
Data type returned
FileSpec: The function returns a FileSpec for the current database file.
The function can also return 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||File not found.|
|$$-50||paramErr||There was an error with the parameter.|
|$$-4215||invalidFMPVersion||This function does not work with this version|
Other errors may be returned.
Troi File Plug-in 1.2
FileMaker Pro 16 to FileMaker Pro 2023
The -CurrentApplication switch of this function works on all platforms and also with a runtime.
The -CurrentFileName switch of this function works on Windows from FileMaker version 5. On macOS it works from FileMaker 4.0 and later. If you use it on Windows under a version earlier than FileMaker 5 an error code “$$-4215” (kErrInvalidFMPVersion) is returned.
IMPORTANT: When creating a runtime with FileMaker Developer on Windows the -CurrentFileName function does NOT work on Windows NT, Windows 2000 and Windows XP. It works with runtimes on macOS and Windows 95/98/Me.
Also when a file is hosted as a guest, for example with FileMaker Server it can not return the path, in this case it will return an error code “$$-43” (fnfErr = file not found).
NOTE FileMaker Pro 5.5 has a Status ( CurrentFilePath ) function, that also returns a path to the file. For FileMaker 7 and later this function is called: Get ( FilePath )
The switch -CurrentAppFolder returns the folder of the current running application. This is for example the folder of the FileMaker Pro application or the folder of the FileMaker runtime application.
IMPORTANT (macOS only) Version 2.7 changed the behavior of the switch “-CurrentApplication”. This function now returns the FSSpec to the FileMaker application package (usually FileMaker Pro.app), instead of the carbon executable inside this package.
So the full path will no longer be:
“MacHD:Applications:FileMaker Pro 6 Folder:FileMaker Pro.app:Contents:MacOS:FileMaker Pro”
Instead it will be:
“MacHD:Applications:FileMaker Pro 6 Folder:FileMaker Pro.app:”
Be aware that the FSSpec of this package is a folder! This may break a script if you assumed the “Contents:MacOS:FileMaker Pro” was at the end. If you only want to find the folder of the FileMaker application use the switch “-CurrentAppFolder”.
“-CurrentAppFolder” will return the path with a backslash (Windows).
Set Field [ result ; TrFile_GetPathTo ( "-CurrentApplication" ) ]
This will get the path to the current FileMaker application. An example result can be on Mac “MyDisk:Applications (Mac OS 9):FileMaker Pro 5.5 Folder:FileMaker Pro”. On Windows this might be: “C:\Program Files\FileMaker\FileMaker Pro 5.5 Folder\FileMaker Pro.exe”
Set Field [ result ; TrFile_GetPathTo ( "-CurrentFileName" ; Get ( FileName ) ; Get ( FileSize ) ) ]
This will get the path to the current FileMaker file that is open. An example result can be on Mac “MyDisk:Documents:test.fmp12”. On Windows this might be: “D:\Documents\test.fmp12”