Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updated to GIT-16-6dff269

...

Examples:

Read mode (byte):;reads

Code Block
titleExample: Reads the entire content of the file

...

linenumberstrue


same => n,Set(foo=${FILE(/tmp/test.txt)})

...



Code Block
titleExample: Reads from the 11th byte to the end of the file (i.e. skips the first 10)

...

linenumberstrue


same => n,Set(foo=${FILE(/tmp/test.txt,10)})

...



Code Block
titleExample: Reads from the 11th to 20th byte in the file (i.e. skip the first 10, then read 10 bytes)

...

linenumberstrue


same => n,Set(foo=${FILE(/tmp/test.txt,10,10)})

Read mode (line):; reads

Code Block
titleExample: Reads the 3rd line of the file

...

linenumberstrue


same => n,Set(foo=${FILE(/tmp/test.txt,3,1,l)})

...



Code Block
titleExample: Reads the 3rd and 4th lines of the file

...

linenumberstrue


same => n,Set(foo=${FILE(/tmp/test.txt,3,2,l)})

...



Code Block
titleExample: Reads from the third line to the end of the file

...

linenumberstrue


same => n,Set(foo=${FILE(/tmp/test.txt,3,,l)})

...



Code Block
titleExample: Reads the last three lines of the file

...

linenumberstrue


same => n,Set(foo=${FILE(/tmp/test.txt,-3,,l)})

...



Code Block
titleExample: Reads the 3rd line of a DOS-formatted file

...

linenumberstrue


same => n,Set(foo=${FILE(/tmp/test.txt,3,1,l,d)})

Write mode (byte):; truncate

Code Block
titleExample: Truncate the file and write

...

bar

...

linenumberstrue


same => n,Set(FILE(/tmp/test.txt)=bar)

...

; Append "bar"



Code Block
titleExample: Append bar
linenumberstrue


same => n,Set(FILE(/tmp/test.txt,,,a)=bar)

...



Code Block
titleExample: Replace the first byte with

...

bar

...

(replaces 1 character with 3)
linenumberstrue


same => n,Set(FILE(/tmp/test.txt,0,1)=bar)

...



Code Block
titleExample: Replace 10 bytes beginning at the 21st byte of the file with

...

bar

...

linenumberstrue


same => n,Set(FILE(/tmp/test.txt,20,10)=bar)

...



Code Block
titleExample: Replace all bytes from the 21st with

...

bar

...

linenumberstrue


same => n,Set(FILE(/tmp/test.txt,20)=bar)

...



Code Block
titleExample: Insert bar after the 4th character
linenumberstrue


same => n,Set(FILE(/tmp/test.txt,4,0)=bar)

Write mode (line):;

Code Block
titleExample: Replace the first line of the file with

...

bar

...

linenumberstrue


same => n,Set(FILE(/tmp/foo.txt,0,1,l)=bar)

...



Code Block
titleExample: Replace the last line of the file with

...

bar

...

linenumberstrue


same => n,Set(FILE(/tmp/foo.txt,-1,,l)=bar)

...



Code Block
titleExample: Append bar to the file with a newline
linenumberstrue


same => n,Set(FILE(/tmp/foo.txt,,,al)=bar)

Info
titleNote

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.

...

This documentation was imported from Asterisk Version GIT-16-b8bf57dc386dff269