TrFile_DeleteFolder (function reference)

By May 26, 2021May 27th, 2021Online Help, Troi File Plug-in
Troi File Plug-in > Functions reference > TrFile_DeleteFolder
Troi File Plug-in for FileMaker Pro


Deletes the folder indicated by the folderPath.

SyntaxFunction badge

TrFile_DeleteFolder ( switches ; folderPath )


switches determines which folders are deleted
folderPath the path to the folder to delete


Switches can be empty or this:

-DeleteAllSubFoldersAndAllContents delete all sub folders and also the contents of those folders
-ForceDelete use in combination with the switch "-DeleteAllSubFoldersAndAllContents". Forcefully deletes any open files inside the folder and subfolders.

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 folder was deleted
$$-1 user CANCELED
$$-37 bdNamErr Bad name in the file system
$$-47 fBsyErr File is busy, can’t delete because it is not empty
$$-50 paramErr Parameter error, check if the supplied parameters are correct.
$$-120 dirNFErr Directory not found, is not a directory or is a file

Other errors may be returned.

Originated in

Troi File Plug-in 2.0


FileMaker Pro 16 to 19


WARNING This is a powerful feature. Be careful what you do! Note also that the folder is not moved to the Trash, but deleted completely. This can not be undone!
See also Dial_Dialog function (of the Troi Dialog plug-in) or use the “Show Message” script step if you want to warn the user.
You can use FileMaker styled paths, like “filemac:/MacHD/folder/subfolder”.
Starting with Troi File Plug-in 12.0 you can omit filemac: or filewin: too! Any path starting with a slash will be parsed as a FileMaker style path (of the platform FileMaker is running).

v13.0 (macOS) Added the switch “-ForceDelete”. When you use this switch in combination with the switch “-DeleteAllSubFoldersAndAllContents” the plug-in will forcefully delete any open files inside the folder and subfolders. This solves a problem where in some cases the function could return error code $$-47 (fBsyErr).


Assume your C disk already contains a folder “TestFold”. We assume that a global number field gErrorCode is defined. Create the following script:

Set Field [ result ; TrFile_DeleteFolder ( "-Unused " ; " C:\TestFold\" ) ]

This script will delete the folder “TestFold”. On macOS the path will be of the form “Mac HD:TestFold:”.

Example 2

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

  gErrorCode		Global, number
  gFolderPath		Global, text

gFolderPath should contain the path to an existing file which you want to delete, for example “D:\Logs\” (Windows) or “Mac HD:Logs:” (Mac). In a script add the following scriptstep:

Set Field [ gErrorCode ; TrFile_DeleteFolder ( "-DeleteAllSubFoldersAndAllContents" ;  gFolderPath ) ]

This will delete the folder from the disk, including contents, like files and folders. The user is always given a warning. If you don’t use this switch only empty folders are deleted.

Used in example file


Related functionsFunction badge


Related script stepScript step badge

Delete Folder

Related topics

Troi File Plug-in online help (overview)

Online Help Page for Troi File Plug-in for 16 to 19 –> TrFile_DeleteFolder (filep4214) 2021-0527 11:06:35