Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
Files.ReadFile
Reads a file with the given path.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
Files | 3.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
MBS( "Files.ReadFile"; FilePath { ; Mode; FileName } ) More
Parameters
Parameter | Description | Example | Flags |
---|---|---|---|
FilePath | The native file path. Something like "/Users/cs/desktop/test.txt" on Mac and "C:\Programs\Data\test.txt" on Windows. Files without path end in the root directory on Mac. | "test.txt" | |
Mode | auto: to auto detect the type of container based on the file name. base64: pass base64 to encode data first to base64 encoding. Base64URL: Base64URL encoding. Hex: Can be Hex to encode to hex encoding. container: the result is returned as a container with a FILE stream inside. jpg: Return as JPEG container. png: Return as PNG container. tif: Return as TIFF container. gif: Return as GIF container. bmp: Return as BMP container. psd: Return as PSD container. pdf: Return as PDF container. This may calculate a preview image. Default is return content as text if you pass "" or ommit the parameter. |
"" | Optional |
FileName | If mode is container, this defines the file name to use. | "test.txt" | Optional |
Result
Returns container value or error.
Description
Reads a file with the given path.Reads the data in the file and returns as text with native encoding. This may truncate the string at the first null byte.
You can optionally define a mode like base64 or Hex to read any bytes including null bytes.
See also Text.ReadTextFile for reading text files with specific encoding.
Reading files over 1 GB is not supported. Use Container.ReadFile for bigger files.
Added new modes with version 5.3: auto, compressed, pdf, png, jpg, tif, gif, bmp or psd.
For reading simple text files, please use Text.ReadTextFile.
See also specialized functions Files.ReadJPEG, Files.ReadPDF, Files.ReadPNG, Text.ReadTextFile and RichText.ReadFile.
For PDF content: If you have a DynaPDF Pro license and DynaPDF functions initialized, this function can add previews for the PDF file on Windows and Linux. For MacOS, we make them with PDFKit.
This function requires a native path. Use Path.FileMakerPathToNativePath to convert a FileMaker path to a native path if required. If you like to have the user choose the path, you can use FileDialog functions.
For Server be aware that server has limited permissions and may not be able to access all files on a computer.
Examples
Read file with some data:
MBS("Files.ReadFile"; $Path )
Read file with some data and encode base64:
MBS("Files.ReadFile"; "/Users/cs/Desktop/test.txt"; "base64")
Read as compressed container:
Set Field [Container Compression::SomeContainer; MBS("Files.ReadFile"; "/Users/cs/Desktop/test.jpg"; "compressed"; "test.jpg")]
Read file on Server:
MBS( "Files.ReadFile"; "C:\Programs\FileMaker Server\Data\Documents\test.pdf")
See also
- Files.CopyFile
- Files.MoveFile
- Files.ReadJPEG
- Files.ReadPDF
- Files.RevealFile
- ImageCapture.Download
- RichText.ReadContainer
- RichText.ReadFile
- RichText.WritePDF
- Text.ReadTextFile
Release notes
- Version 10.3
- Added Base64URL as output option for RSA.Sign, CURL.ReceiveData, Files.ReadFile, Hash.DigestFile, Hash.Digest, Encryption.Cipher and for other functions as text encoding parameter.
Example Databases
- CURL/WebServices/WeatherBit.io test
- Drag and Drop/DragTest Popover
- Drag and Drop/DragTest
- Drag and Drop/for Mac/DragTest multiple picture files
- Mac and iOS/Machine Learning/Core ML Photos
- Mac and iOS/PDFKit/PDF Merge Shrink Tool
- Mac only/ImageCapture/Camera Import
Blog Entries
- MBS FileMaker Advent calendar - Door 20 - Scan and Recognize
- MBS FileMaker Advent calendar - Door 3 - Drag & Drop
- MBS Plugin Advent calendar: 12 - Files
- MBS FileMaker Plugin, version 10.3pr1
- FileMaker 18 File Script Steps vs. BinaryFile functions
- Adding Drag and Drop receiver to a layout
- [ANN] MBS FileMaker Plugin 5.3 for OS X/Windows
- MBS FileMaker Plugin, version 5.3pr4
- Compressed Containers
- MBS Filemaker Plugin, version 4.4pr6
This function is free to use.
Created 18th August 2014, last changed 25th October 2024
