123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- <!DOCTYPE html>
- <html>
- <head>
- <title>Asterisk Project : Asterisk 13 Function_FILE</title>
- <link rel="stylesheet" href="styles/site.css" type="text/css" />
- <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
- </head>
- <body class="theme-default aui-theme-default">
- <div id="page">
- <div id="main" class="aui-page-panel">
- <div id="main-header">
- <div id="breadcrumb-section">
- <ol id="breadcrumbs">
- <li class="first">
- <span><a href="index.html">Asterisk Project</a></span>
- </li>
- <li>
- <span><a href="Asterisk-13-Command-Reference_29394274.html">Asterisk 13 Command Reference</a></span>
- </li>
- <li>
- <span><a href="Asterisk-13-Dialplan-Functions_29394287.html">Asterisk 13 Dialplan Functions</a></span>
- </li>
- </ol>
- </div>
- <h1 id="title-heading" class="pagetitle">
- <span id="title-text">
- Asterisk Project : Asterisk 13 Function_FILE
- </span>
- </h1>
- </div>
- <div id="content" class="view">
- <div class="page-metadata">
-
-
-
-
-
-
-
- Created by <span class='author'> wikibot</span> on Aug 08, 2014
- </div>
- <div id="main-content" class="wiki-content group">
- <h1 id="Asterisk13Function_FILE-FILE()">FILE()</h1>
- <h3 id="Asterisk13Function_FILE-Synopsis">Synopsis</h3>
- <p>Read or write text file.</p>
- <h3 id="Asterisk13Function_FILE-Description">Description</h3>
- <p>Read and write text file in character and line mode.</p>
- <p>Examples:</p>
- <p>Read mode (byte):</p>
- <p>;reads the entire content of the file.</p>
- <p>Set(foo=${FILE(/tmp/test.txt)})</p>
- <p>;reads from the 11th byte to the end of the file (i.e. skips the first 10).</p>
- <p>Set(foo=${FILE(/tmp/test.txt,10)})</p>
- <p>;reads from the 11th to 20th byte in the file (i.e. skip the first 10, then read 10 bytes).</p>
- <p>Set(foo=${FILE(/tmp/test.txt,10,10)})</p>
- <p>Read mode (line):</p>
- <p>; reads the 3rd line of the file.</p>
- <p>Set(foo=${FILE(/tmp/test.txt,3,1,l)})</p>
- <p>; reads the 3rd and 4th lines of the file.</p>
- <p>Set(foo=${FILE(/tmp/test.txt,3,2,l)})</p>
- <p>; reads from the third line to the end of the file.</p>
- <p>Set(foo=${FILE(/tmp/test.txt,3,,l)})</p>
- <p>; reads the last three lines of the file.</p>
- <p>Set(foo=${FILE(/tmp/test.txt,-3,,l)})</p>
- <p>; reads the 3rd line of a DOS-formatted file.</p>
- <p>Set(foo=${FILE(/tmp/test.txt,3,1,l,d)})</p>
- <p>Write mode (byte):</p>
- <p>; truncate the file and write "bar"</p>
- <p>Set(FILE(/tmp/test.txt)=bar)</p>
- <p>; Append "bar"</p>
- <p>Set(FILE(/tmp/test.txt,,,a)=bar)</p>
- <p>; Replace the first byte with "bar" (replaces 1 character with 3)</p>
- <p>Set(FILE(/tmp/test.txt,0,1)=bar)</p>
- <p>; Replace 10 bytes beginning at the 21st byte of the file with "bar"</p>
- <p>Set(FILE(/tmp/test.txt,20,10)=bar)</p>
- <p>; Replace all bytes from the 21st with "bar"</p>
- <p>Set(FILE(/tmp/test.txt,20)=bar)</p>
- <p>; Insert "bar" after the 4th character</p>
- <p>Set(FILE(/tmp/test.txt,4,0)=bar)</p>
- <p>Write mode (line):</p>
- <p>; Replace the first line of the file with "bar"</p>
- <p>Set(FILE(/tmp/foo.txt,0,1,l)=bar)</p>
- <p>; Replace the last line of the file with "bar"</p>
- <p>Set(FILE(/tmp/foo.txt,-1,,l)=bar)</p>
- <p>; Append "bar" to the file with a newline</p>
- <p>Set(FILE(/tmp/foo.txt,,,al)=bar)</p>
- <div class="aui-message hint shadowed information-macro">
- <p class="title">Note</p>
- <span class="aui-icon icon-hint">Icon</span>
- <div class="message-content">
-
- <p>If <code>live_dangerously</code> in <code>asterisk.conf</code> is set to <code>no</code>, this function can only be executed from the dialplan, and not directly from external protocols.</p>
- </div>
- </div>
- <h3 id="Asterisk13Function_FILE-Syntax">Syntax</h3>
- <div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
- <pre>FILE(filename,offset,length,options,format)</pre>
- </div></div>
- <h5 id="Asterisk13Function_FILE-Arguments">Arguments</h5>
- <ul>
- <li><code>filename</code></li>
- <li><code>offset</code> - Maybe specified as any number. If negative, <em>offset</em> specifies the number of bytes back from the end of the file.</li>
- <li><code>length</code> - If specified, will limit the length of the data read to that size. If negative, trims <em>length</em> bytes from the end of the file.</li>
- <li><code>options</code>
- <ul>
- <li><code>l</code> - Line mode: offset and length are assumed to be measured in lines, instead of byte offsets.</li>
- <li><code>a</code> - In write mode only, the append option is used to append to the end of the file, instead of overwriting the existing file.</li>
- <li><code>d</code> - 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.</li>
- </ul>
- </li>
- <li><code>format</code> - The <em>format</em> parameter may be used to delimit the type of line terminators in line mode.
- <ul>
- <li><code>u</code> - Unix newline format.</li>
- <li><code>d</code> - DOS newline format.</li>
- <li><code>m</code> - Macintosh newline format.</li>
- </ul>
- </li>
- </ul>
- <h3 id="Asterisk13Function_FILE-SeeAlso">See Also</h3>
- <ul>
- <li><a href="Asterisk-13-Function_FILE_COUNT_LINE_29394642.html">Asterisk 13 Function_FILE_COUNT_LINE</a></li>
- <li><a href="Asterisk-13-Function_FILE_FORMAT_29394643.html">Asterisk 13 Function_FILE_FORMAT</a></li>
- </ul>
- <h3 id="Asterisk13Function_FILE-ImportVersion">Import Version</h3>
- <p>This documentation was imported from Asterisk Version SVN-branch-13-r420538</p>
- </div>
-
-
- </div> </div>
- <div id="footer">
- <section class="footer-body">
- <p>Document generated by Confluence on Aug 11, 2014 13:46</p>
- </section>
- </div>
- </div> </body>
- </html>
|