TrFile_DeleteFile (function reference)

By May 1, 2017May 20th, 2020Online Help, Troi File Plug-in
Troi File Plug-in > Functions reference > TrFile_DeleteFile
Troi File Plug-in for FileMaker Pro

TrFile_DeleteFile

Deletes the file indicated by the filePath. This function requires no user intervention.

SyntaxFunction badge

TrFile_DeleteFile ( switches ; filePath )

Parameters

switchesmodifies the action of the function
filePaththe path to the file to delete

Switches

Switches can be empty or:

-ForceDeleteforcefully delete the file even if it is busy (open by an other application).

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:

0no errorThe file was deleted
$$-43fnfErrThe file was not found
$$-47fBsyErrThe file is in use
$$-1genericErrThe file could not be deleted

Other errors may be returned.

Originated in

Troi File Plug-in 1.0

Compatibility

FileMaker Pro 15 to 19

Considerations

WARNING: The file is not moved to the Trash, but deleted completely. This can not be undone!
See also the 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 “filewin:/C:/MyFiles/test.txt”.
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).
v12.0 added the -ForceDelete switch to forcefully delete the file even if it is busy. This solves a problem where in some cases the OS would keep a file busy for too long (giving error code $$-47 fBsyErr).

Example

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

Set Field [ gErrorCode ; TrFile_DeleteFile ( "-Unused" ; "C:\TestFile.xls" ) ]

This script will delete the file “TestFile.xls”. On Mac OS the path will be of the form “Mac HD:TestFile.xls”.

Example 2

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

  gErrorCode		Global, number
  gFilePath		Global, text

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

Set Field [ gErrorCode ; TrFile_DeleteFile ( "-Unused" ;  gFilePath ) ]

This will delete the file from the disk.

Related functionsFunction badge

TrFile_CreateFile
TrFile_SelectFileDialog

Related script stepScript step badge

Delete File

Related topics

Troi File Plug-in online help (overview)


Online Help Page for Troi File Plug-in for 15 to 19 –> TrFile_DeleteFile (filep4213) 2020-0520 15:59:02