File Functions in DIAL
The file functions in DIAL perform various local file manipulations, including writing to local files.
Opens the file named filename, and creates a special Object Variable file to represent it. If the file does not exist, it is created. The options argument is a string value that contains a comma-separated list of options.
Supported options include:
Delimiter Options | Description |
---|---|
delim=comma | Uses a comma delimiter when writing fields to the specified file. |
delim=tab | Uses a tab delimiter when writing fields to the specified file. (Default) |
delim=<character> | Use the specified character as a delimiter when writing fields to the specified file. |
File Options | Description |
---|---|
write | Opens the file for writing. |
truncate | Opens the file for writing and clears the current contents of the file. (Default) |
append | Opens the file for writing without clearing the current contents of the file. |
Closes the file stored in the special Object Variable file.
Returns true if the file exists, false otherwise. A directory is not considered a file. This function can test the success of an Integrator or Build process by determining if the file created by that process exists.
Concatenates the named local text files, filename1, filename2, into a new file named dest_file.
TIP: For pdf files, consider a third party tool such as pdfbox-app.jar to concatenate pdf files. See https://pdfbox.apache.org/download.cgi.
Deletes the specified filename from the local file system.
Reads a line from the file stored in the special Object Variable file and returns the line as a string without the ending carriage return or new line.
Writes the specified string to the file stored in the special Object Variable file.
Writes the specified string, followed by a new line, to the file stored in the special Object Variable file.
Writes the specified values, value1, value2, followed by a new line, to the file stored in the special Object Variable file. The values are separated by the current delimiter.
Example 1:
This example demonstrates the action required to open a file called output.txt.
file.open(file,"../data/output.txt","write, delim=comma");
Example 2:
This example concatenates two files into one destination file, which is listed last.
file.concat(file.concat("../data/output.txt", "../data/20090212.txt", "../data/new_file.txt");
Example 3:
This example removes a file named revbymgr.txt from the local file system
file.remove("../temp/revbymgr.txt");
Example 4:
This example opens a file named output.txt and writes in the values a1, b1, c1, a2, b2, and c2 to the file, stored in the object variable file. The values are separated by the current delimiter, which is a comma.
file.open(file,"../data/output.txt","write,truncate,delim=comma");
file.write_fields(file,"a1","b1","c1");
file.write_fields(file,"a2","b2","c2");
file.close(file);