JavaScript global method: writeFile

Writes data to the local file system.

Syntax

writeFile( path, mode, object );

Arguments

The following arguments are valid for this function:

Argument Data type Required Description
path String Yes This argument contains the text string or variable value containing the fully qualified path of the file to be written. You must enclose literal text strings in quotation marks.
mode String No Use the string "b" to write a binary file. Use the string "ba" to append to a binary file. Use the string "a" to append to a text file. Use any other string or omit the parameter to write to a text file. This is the default. The values are case sensitive and only the values specified are valid.
object String Yes This parameter contains the text string or variable value containing the data you want to write to a file.

Return values

A number representing the number of bytes written to a file.

Description

This method writes the contents of the object parameter to the file specified in the path parameter. The file can be in binary format or text format as determined by the binary parameter.

Example

This example does the following:

  • Writes the list of currently logged on users to a file

This example requires the following sample data:

  • The list of currently logged on users stored in system.users
var userList = system.users;
var filePath;
var isMode;
var fileObject;

function writeToFile( path, binary, object )
{
 print( "Writing " + path + " to file..." );
 var output = writeFile( path, mode, object );
 print( "The number of bytes written to file was: " + output );
 return output
}

filePath = "C:\\users.xml";
isMode = null;
fileObject = userList;
writeToFile( filePath, isMode, fileObject );