Skip to end of metadata
Go to start of metadata

FILE()

Synopsis

Read or write text file.

Description

Read and write text file in character and line mode.

Examples:

Read mode (byte):

Example: Reads the entire content of the file
Example: Reads from the 11th byte to the end of the file (i.e. skips the first 10)
Example: Reads from the 11th to 20th byte in the file (i.e. skip the first 10, then read 10 bytes)

Read mode (line):

Example: Reads the 3rd line of the file
Example: Reads the 3rd and 4th lines of the file
Example: Reads from the third line to the end of the file
Example: Reads the last three lines of the file
Example: Reads the 3rd line of a DOS-formatted file

Write mode (byte):

Example: Truncate the file and write bar
Example: Append bar
Example: Replace the first byte with bar (replaces 1 character with 3)
Example: Replace 10 bytes beginning at the 21st byte of the file with bar
Example: Replace all bytes from the 21st with bar
Example: Insert bar after the 4th character

Write mode (line):

Example: Replace the first line of the file with bar
Example: Replace the last line of the file with bar
Example: Append bar to the file with a newline

Note

Icon

If live_dangerously in asterisk.conf is set to no, this function can only be executed from the dialplan, and not directly from external protocols.

Syntax

FILE(filename,offset,length,options,format)
Arguments
  • filename
  • offset - Maybe specified as any number. If negative, offset specifies the number of bytes back from the end of the file.
  • length - If specified, will limit the length of the data read to that size. If negative, trims length bytes from the end of the file.
  • options
    • l - Line mode: offset and length are assumed to be measured in lines, instead of byte offsets.
    • a - In write mode only, the append option is used to append to the end of the file, instead of overwriting the existing file.
    • d - In write mode and line mode only, this option does not automatically append a newline string to the end of a value. This is useful for deleting lines, instead of setting them to blank.
  • format - The format parameter may be used to delimit the type of line terminators in line mode.
    • u - Unix newline format.
    • d - DOS newline format.
    • m - Macintosh newline format.

See Also

Import Version

This documentation was imported from Asterisk Version GIT-16-6dff269

  • No labels