Skip to main content

TrFile_SetFileAttribute (function reference)

Troi File Plug-in > Functions reference > TrFile_SetFileAttribute
Troi File Plug-in for FileMaker Pro

TrFile_SetFileAttribute

Sets an attribute of the file specified by the filePath.

SyntaxFunction badge

TrFile_SetFileAttribute ( switches ; filePath ; cftype ; comment )

Parameters

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

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)

For files and folders on iCloud Drive can you use:

-iCloudStartDownloadingItem starts the download of a file on iCloud Drive to the local disk (macOS only)
-iCloudRemoveLocalCopy remove the local copy of a file on the iCloud Drive (macOS only)

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 2.0

Compatibility

FileMaker Pro 16 to FileMaker Pro 2023

Considerations

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.
v14.0 added the switches “-iCloudStartDownloadingItem” and “-iCloudRemoveLocalCopy”.

Example

Set Variable [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

Attribute.fmp12

Related functionFunction badge

TrFile_GetFileAttribute

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 2023 –> TrFile_SetFileAttribute (filep4282) 2023-0601 16:02:14