filesave
PATH
,
DATA

The filesave statement saves data directly into a disk file.


Parameters

This statement has two parameters:

path – is a path to the file to be saved, including the file name (see Files and Folders for more information about file paths).

data – is the actual data that will be placed into the file. This may be in a field, variable, or constructed with a formula. This parameter should be binary data. If the parameter is text, it will automatically be converted to binary data using UTF-8 (unicode) encoding. If you want to use a different encoding method you must use the texttobinary( function.


Description

This statement saves data directly into a disk file. Using this statement you can create any kind of disk file you want. If the file does not already exist it will be created. If it does already exist its contents will be replaced! If you want to add to the contents of the file, use the fileappend statement.

This example creates a file named demo.txt in the Documents folder. The file contains the sentence Hello, this is a test.

filesave "~/Documents/demo.txt","Hello, this is a test."

You can use a complex formula to create the data to save. In this example, the Time Stamp.log file will contain the current date and time:

filesave "~/Library/Logs/Time Stamp.log",
    datepattern( today(),"mm/dd/yy ")+"@"+timepattern( now(),"hh:mm:ss am/pm")

The filesave statement can create any kind of file, but text files are the most common. If the data formula calculates a text value, the text will automatically be converted to binary data using UTF-8 (unicode) encoding. If you want to use a different encoding method you must use the texttobinary( function, as shown in this example:

filesave "~/Documents/MyWebSite/index.html",
    texttobinary("Welcome! Bienvenue! Willkommen!","ISO Latin")
Legacy Four Parameter Syntax

Previous versions of Panorama (version 6 and before) used a four parameter format for the filesave statement:

filesave folder,filename,typecreatorcode,data

For compatibility with existing databases, this format still works. Here is an example:

filesave dbsubfolder("Logs"),datepattern(today(),"YYYYMMDD")+".log",TEXT    ",DataLogVariable

If the filename has an extension (.txt, .html, .css, .csv, etc.) then the typecreatorcode parameter is ignored (and you can leave it blank). If there is no extension, Panorama will add one based on the typecreatorcode supplied. For example, the code below will create a file named example.txt, not example.

filesave dbfolder(),"example","TEXT    ",exampleTextVariable

The filesave statement does NOT set the file’s OS 9 type/creator code. Current versions of Panorama only work with file extensions, not type/creator codes.


See Also


History

VersionStatusNotes
10.0UpdatedCarried over from Panorama 6.0 but now uses a 2 parameter syntax. (The old 4 parameter syntax is still available.)