Overview

Use the external file object to work with files in the Expression Engine Language (EEL). Read and Write operations are supported in the file object and there are additional functions for manipulating and working with files.

Overview of the File Object

The file object can be used to open, read, and write files. A file is opened using the file object. For example:
File f
f.open("c:\filename.txt","r")
In this example, the OPEN() function opens filename.txt. The mode for opening the file is read. Other modes are "a" (append to end of file) and "w" (write). A combination of these switches can be used.

Executing Programs and File Commands

To execute programs, use the EXECUTE() function:
execute(string)
For example, the following code changes the default permissions of a text file created by the Data Job Editor.
To execute the command in Microsoft Windows, enter:
execute("/bin/chmod", "777", "file.txt")
Or, to execute from the UNIX shell, enter:
execute("/bin/sh", "-c", "chmod 777 file.txt")

Running a Batch File By Using Execute Function

To invoke the MS-DOS command prompt, call the cmd.exe file. For example:
//Expression
execute("cmd.exe", "/q" ,"/c", C:\BatchJobs.bat");
The following parameters can be declared:
  • /q — turns echo off
  • /c — Executes the specified command for the MS-DOS prompt and then closes the prompt
Note: The expression engine handles the backslash character differently; it does not need to be escaped.
For example: "C:\\Program Files\\DataFlux" should now be entered as "C:\Program Files\DataFlux"