Module Files

The Files module provides rudimentary functions for testing the existence of a file, saving and loading pages and strings to and from files, and downloading web content to a file. The filename argument to each of the functions in See Module Files is a filename in the syntax supported by the file system underlying WebL.

The combination of the SaveToFile and Eval functions allows some limited persistant storage for WebL. For example, the following program writes a set out to disk and reads it back in again to the variable T:

import Files;

 

var S = {1, 2, 4, 6};

Files_SaveToFile("test.tmp", ToString(S));

var T = Files_Eval("test.tmp")

 

Note that this technique can be used only for externalizing non-recursive values that do not contain functions or methods -- the external format of those structures are not legal WebL programs.

 

Module Files

Function

Description

AppendToFile(filename: string, val: string): nil

Appends val to the end of the file.

AppendToFile(filename: string, val: string, charset: string): nil

As above, but sets the character encoding to use. Typical encodings are "iso-8859-1", "UTF8", etc.

Exists(filename: string): bool

Determines if a file with the specified name exists.

LoadFromFile(filename: string, mimetype: string): page

Loads a page object from a file.

LoadStringFromFile(filename: string): string

Loads a file as a string object.

SaveToFile(filename: string, val: string): nil

Saves the string val to the specified file.

SaveToFile(filename: string, val: string, charset: string): nil

As above, but overrides the default character encoding of the saved file. Typical encodings are "iso-8859-1", "UTF8", etc.

GetURL(url: string, filename: string): page
GetURL(url: string, filename: string, param: {object,string}): page
GetURL(url: string, filename: string, param: {object,string}, header: object): page
GetURL(url: string, filename: string, param: {object,string}, header: object, options: object): page

Similar to the built-in GetURL function except that the retrieved document is saved to the indicated file. The url, param, header and option arguments are the same as the built-in GetURL function.

PostURL(url: string, filename: string): page
PostURL(url: string, filename: string, param: {object,string}): page
PostURL(url: string, filename: string, param: {object,string}, header: object): page
PostURL(url: string, filename: string, param: {object,string}, header: object, options: object): page

Similar to the built-in PostURL function except that the retrieved document is saved to the indicated file. The url, param, header and options arguments are the same as the built-in PostURL function.

Eval(filename: string): any

The cotnets of filename is evaluated as a WebL program. The result returned is the value of the last statement in the program.

List(dirname: string): list

Returns the file names and directory names contained in directory dirname.

IsDir(name: string): bool

Checks whether name is a valid directory name or not.

IsFile(name: string): bool

Checks whether name is a valid file name or not.

Mkdir(name: string): bool

Attempts to create a new directory called name, and returns success or failure.

Delete(name: string): bool

Attempts to delete the file called name, and returns success or failure.


Up Previous Next