Set File Attributes |
Sets an attribute of the file specified by the filePath.
Syntax
Set File Attributes [ Select ; Result (error) ; FilePath ; Lock ;
Visibility ; Archive bit ; Finder label ]
Options
Select entire contents | replaces the entire contents of a field with the result. If not checked the result replaces the currently selected portion of the field |
Result (error) | an error code |
FilePath | the path to the file |
Lock | On/Off/Don’t Change |
Visibility | Make visible/Hide/Don’t Change |
Archive bit | Set/Clear/Don’t Change |
Finder label | "No label" or 1 (Gray) to 9 (Orange) or Don’t Change |
Returned Result
Data type returned
Error code
Result
The returned result is 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:
0 | no error | The attribute was set. |
$$-43 | fnfErr | File not found. |
$$-50 | paramErr | There was an error with the parameter. |
$$-1 | genericErr | An unspecified error occurred. |
Other errors may be returned.
Originated in
Troi File Plug-in 9.0
Compatibility
FileMaker Pro 17 to FileMaker Pro 21 (2024)
Considerations
You can set the label of a folder too.
Example
Set File Attributes [ Select ; gErrorCode ; "C:\test.doc" ; Lock: On ]
The file will be locked (made read-only) and the result will be 0 (provided the file exists).
Set File Attributes [ Select ; $ErrorCode ; "HD:data:test.doc" ; Visibility: Hide ]
The file will become hidden.
Set File Attributes [ Select ; $ErrorCode ; "HD:data:test.doc" ;
Visibility: Make visible ; Label: 2 (Green) ]
The file will become visible and the label in the Finder will be set to 2 (Green).
Example 2
We assume that in your FileMaker file the following fields are defined:
gFilePath Global, text
gLockIt Global, number (used as a boolean value)
gErrorCode Global, number
gFilePath should contain the path to an existing file, for example “D:\Out.txt” (Windows) or “Mac HD:Out.txt” (Mac). In a script add the following script step:
If [ gLockIt = 1 ]
Set File Attributes [ Select ; gErrorCode ; gFilePath ; Lock: On ]
Else
Set File Attributes [ Select ; gErrorCode ; gFilePath ; Lock: Off ]
End If
This will make the file locked if gLockIt is 1 and unlocked otherwise.
Related functions
TrFile_GetFileAttribute |
TrFile_SetFileAttribute |
Related topics
Troi File Plug-in online help (overview)