YOUSEFUL / FILEMAKER

Youseful File: FAQ, examples and tutorial

Learning center · Core reference · Extended reference

Use YsflFile.fmx64 for native Windows file paths, text and container I/O, searching, images and folder watching. The examples below need no database fields.

FAQ

Which path format should I use? Use native Windows paths. To convert a FileMaker path, call YsflFi_PathInfo ( $fmPath ; "native" ). Build native paths with PathJoin and SpecialFolder when possible. Literal backslashes must be escaped in FileMaker calculations.

Does Write return 0 when it succeeds? It returns the number of bytes written. A negative value is an error. Several other original commands, including New, Copy and Delete, return 0 on success. Read returns text or ?; inspect YsflFi_Get ( "lastError" ) immediately after an original file operation.

Should I read PDFs or images as text? Use ReadContainer and WriteContainer for binary content. Read and Write are for text. A container preserves its file name and binary bytes.

Will WatchStart run a script when a file changes? It creates a watcher. Your script must call WatchPoll to retrieve changes and WatchStop when finished.

Examples

Build a path without touching the disk:

filemaker
YsflFi_PathJoin ( "C:\\Data" ; "Reports" ; "sales.csv" )

Result: the native path C:\Data\Reports\sales.csv. The folders need not exist for this calculation to work.

Get the extension, without its dot:

filemaker
YsflFi_PathInfo ( "C:\\Data\\sales.csv" ; "extension" )

Result: csv.

Tutorial

Standalone sample scripts: Text export.

Goal: write a temporary text export, read it back, and remove just that file.

  1. Create a script named Youseful - Text export in your practice file.
  2. Add these steps. TempPath supplies a new path; Write creates the file.
filemaker
Set Variable [ $path ; Value: YsflFi_TempPath ( "youseful-demo-" ; "txt" ) ]
If [ Left ( $path ; 1 ) = "?" ]
    Show Custom Dialog [ "Path error" ; $path ]
    Exit Script [ Text Result: $path ]
End If
Set Variable [ $content ; Value: "Name,Quantity¶Widget,3" ]
Set Variable [ $written ; Value: YsflFi_Write ( $path ; $content ) ]
If [ $written < 0 ]
    Show Custom Dialog [ "Write failed" ; YsflFi_Get ( "lastErrorMessage" ) ]
    Exit Script [ Text Result: $written ]
End If
Set Variable [ $readBack ; Value: YsflFi_Read ( $path ) ]
Set Variable [ $readError ; Value: YsflFi_Get ( "lastError" ) ]
Set Variable [ $readMessage ; Value: YsflFi_Get ( "lastErrorMessage" ) ]
Set Variable [ $removed ; Value: YsflFi_Delete ( $path ) ]
If [ $readError <> 0 ]
    Show Custom Dialog [ "Read failed" ; $readMessage ]
Else
    Show Custom Dialog [ "Export contents" ; $readBack ]
End If
If [ $removed <> 0 ]
    Show Custom Dialog [ "Cleanup needed" ; "Remove the sample file: " & $path ]
End If
  1. Run the script. The dialog should contain two lines: Name,Quantity and Widget,3. The temporary file should then be gone.

This example deletes only the path it just generated. Delete also supports recursive folder deletion; do not replace this path with a production folder.

Troubleshooting

If Write fails, check folder permissions and disk space. If a path contains the wrong separators, inspect the actual path variable, not its escaped source text. Keep error capture next to the operation; File's original error slot and extended function errors are distinct internally.