Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server (Not)   Client   Old   Guides   Examples
New in version: 6.1   6.2   6.3   6.4   6.5   7.0   7.1   7.2   7.3   7.4    Statistic  

Files.ReadFile

Reads a file with the given path.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
Files 3.5 Yes Yes Yes Yes Yes

MBS( "Files.ReadFile"; FilePath { ; mode; filename } )

Parameters

Parameter Description Example value
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 Optional
Can be base64 to encode data first to base64 encoding. Or can be Hex to encode to hex encoding. If filter is "container", the result is returned as a container with a FILE stream inside. Version 5.3 supports filter "auto" to auto detect the type of container.
"Base64"
filename Optional
If filter is container, this defines the file name to use.
"test.txt"

Result

Returns text or an error message.

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.
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 Files.ReadJPEG, Files.ReadPDF, Files.ReadPNG, Text.ReadTextFile and RichText.ReadFile.

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 decode 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")]

See also


Files.MoveToTrash   -   Files.ReadJPEG

Feedback: Report problem or ask question.




Links
MBS Xojo Plugins