Tutorial

Getting Started with Macros

Macro Editor

User Interface

Menus and Toolbar

Editing Macros

Macro Debugging

How To

Using variables

Finding and modifying objects

Creating new page content

Asking for user input

Storing persistent data

Using binary data

Sorting objects

Macro menus

Bulleted and numbered lists

Accessing the file system

Sample Macros

Concepts

Expressions

Objects

Properties

Variables

Data Types

Arrays

Functions

Literals

Operators

Comments

Last updated on: February 02, 2025
Also available as a single HTML file

Onetastic Macro Documentation > Functions > File System Functions > FileSystem_WriteToFile

FileSystem_WriteToFile

Writes contents to the given file in either binary or text mode. If the file does not exist, it is created. If it exists, its contents are replaced with the given content. Returns true if contents were written successfully.

Syntax

Bool FileSystem_WriteToFile(
	File|String file, 
	Binary|String data, 
	String mode)

Parameters

File|String file
File to write to. This can either be a File object or a String that contains the full path to the file.
Binary|String data
The data to write to the file.
String mode
Write mode that indicates binary or the text encoding of the file. Possible values are: binary, utf8, utf16.

Remarks

See below for the how the file is written based on "data" and "mode" parameters:
Type of data Value of mode Data is written as
Binary binary, utf8, utf16 binary
String binary, utf8 UTF-8
utf16 UTF-16
Any other type for "mode" parameter is converted to String while calling the function.

Examples

// Show the file picker to get a file name and location from user, suggest "file.txt" as the default name $file = FileSystem_ShowSaveFileDialog("file.txt") if (IsObject($file)) // Write current page contents to the file FileSystem_WriteToFile($file, GetCurrentPage().outlines[0].text, "utf8") // Get the first image on the page $image = GetCurrentPage().images[0] // Use its format to provide extension and file type to the picker: $types["Image files"] = "*." & $image.format // Show the file picker to get a file name and location from user $file = FileSystem_ShowSaveFileDialog("image." & $image.format) if (IsObject($file)) // Save the image to this file FileSystem_WriteToFile($file, $image.data, "binary")

Reference

Statements

Hierarchy Objects

Page Objects

Other Objects

Functions

Array Functions

Color Functions

Data Store Functions

Date/Time Functions

Dialog Box Functions

File System Functions

Macro Execution Functions

Macro Menu Functions

Object Functions

Special Functions

String Functions

Window Functions