File Helper

The File Helper file contains functions that assist in working with files.

Loading this Helper

This helper is loaded using the following code:

rigLoadHelper "file"

The following handlers are available:

rigReadFile("path")

Returns the data contained in the file specified in the path with translated end-of-line markers. Example:

put rigReadFile("./path/to/file.lc") into tString

The path can be a relative or full server path. Returns FALSE (boolean) on failure.

Note: The path is relative to your main site index.lc file, NOT your controller or view files. revIgniter uses a front controller so paths are always relative to the main site index.

rigReadBinFile("path")

Same as above but without translation of end-of-line markers.

rigWriteFile("path", tData)

Writes data to the file specified in the path. If the file does not exist the function will create it. Example:

put "Some file data" into tData

if rigWriteFile("./path/to/file.lc", tData) is FALSE then
  put "Unable to write the file" into gData["writeResult"]
else
  put "File written!" into gData["writeResult"]
end if

Note: In order for this function to write data to a file its file permissions must be set such that it is writable (666, 777, etc.). If the file does not already exist, the directory containing it must be writable.

Note: The path is relative to your main site index.lc file, NOT your controller or view files. revIgniter uses a front controller so paths are always relative to the main site index.

rigDeleteFiles "path"

Deletes aLL files contained in the supplied path. Example:

rigDeleteFiles "./path/to/directory/"

If the second parameter is set to TRUE, any directories contained within the supplied root path will be deleted as well. Example:

rigDeleteFiles "./path/to/directory/", TRUE

Use an optional third parameter to determine a name of files to be excluded.

Note: The files must be writable or owned by the system in order to be deleted.

rigGetFileNames("path/to/directory/")

Takes a server path as input and returns an array containing the names of all files contained within it. The file path can optionally be added to the file names by setting the second parameter to TRUE. Any sub-folders contained within the specified path are read as well if the third parameter is set to TRUE.

rigGetDirFileInfo("path/to/directory/")

Reads the specified directory and builds an array containing the filenames, filesize, dates, and permissions. The file path can optionally be added to the file names by setting the second parameter to TRUE. Any sub-folders contained within the specified path are read as well if the third parameter is set to TRUE.

rigGetFileInfo("path/to/file", tFileInformation)

Given a file and path, returns the name, path, size, date modified as an array. Second parameter allows you to explicitly declare what information you want returned; options are: fileName, serverPath, fileSize, resourceSize, created, lastModified, lastAccessed, lastBackedUp, owner, groupOwner, permissions, fileType. Returns FALSE if the file cannot be found.

rigGetMimeByExtension("file")

Translates a file extension into a mime type based on config/mimes.lc. Returns FALSE if it can't determine the type, or open the mime config file.

put "somefile.png" into tFile
put tFile && "has a mime type of" && rigGetMimeByExtension(tFile) into gData["mimeType"]

Note: This is not an accurate way of determining file mime types, and is here strictly as a convenience. It should not be used for security.

rigSymbolicPermissions(tPerms)

Takes an octal value representing a file's permissions and returns standard symbolic notation of file permissions.

put rigSymbolicPermissions(644) into tPerms

# rw-r--r--