TrFile_SetFileAttribute (function reference)

By January 1, 2021January 26th, 2021Online Help, Troi File Plug-in
Troi File Plug-in > Functions reference > TrFile_SetFileAttribute
Troi File Plug-in for FileMaker Pro


Sets an attribute of the file specified by the filePath.

SyntaxFunction badge

TrFile_SetFileAttribute ( switches ; filePath ; cftype ; comment )


switches these determine the attribute that is set
filePath the path to the file
cftype (only for creator, file type) the 4 letter Creator or File Type code
comment (only for Finder comment) the text of the comment to set


switches can be one ore more of the following:

-Lock make the file locked (macOS) or Read-only (Windows)
-Unlock make the file unlocked (macOS) or remove the Read-only attribute (Windows)
-Hide make the file hidden (invisible)
-Unhide unhide the file (visible)
-SetArchive set the file’s archive bit (Windows only)
-ResetArchive reset the file’s archive bit (Windows only)
-LabelNum=X set the label number of a file or folder (macOS only)
-Findercomment set the the Finder comment of a file (macOS only)
-Creator set the 4 letter Creator of a file (macOS only)
-Filetype set the 4 letter FileType of a file (macOS only)

Returned Result

Data type returned

Error code


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 2.0


FileMaker Pro 16 to 19


You’ll get a parameter error ($$-50) if you try to do opposite actions at the same time, like “-unlock -lock”.

If you specify “0000” (4 zero’s) for the cftype the creator or file type will be set to empty.

From v6.0 you can set the label of a folder too.


Set Field [result ; TrFile_SetFileAttribute ( "-lock" ; "C:\test.doc" ) ]

The file will be locked (made Read-Only) and the result will be 0 (provided the file exists).

Set Field [ result ; TrFile_SetFileAttribute ( "-creator" ; "NELL:data:test.doc" ; "MSIE" ) ]
Set Field [ result ; TrFile_SetFileAttribute ( "-filetype" ; "NELL:data:test.doc" ; "TEXT" ) ]

The file’s Creator and FileType will be changed to an Internet Explorer text file.

Example 2

We assume that in your FileMaker file the following fields are defined:

    gFileSpec		Global, text
    gLockIt		Global, number  (used as a boolean value)
    gErrorCode		Global, number

gFileSpec 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:

Set Field [ gErrorCode ; TrFile_SetFileAttribute (
     			If ( gLockIt = 1 , "-lock" , "-unlock" ) ; gFileSpec ) ]

This will make the file locked if gLockIt is 1 and unlocked otherwise.

Used in example file


Related functionFunction badge


Related script stepScript step badge

Set File Attributes

Related topics

Troi File Plug-in online help (overview)

Online Help Page for Troi File Plug-in for 16 to 19 –> TrFile_SetFileAttribute (filep4282) 2021-0126 11:03:45