Asterisk-13-Function_FILE_29394641.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Asterisk Project : Asterisk 13 Function_FILE</title>
  5. <link rel="stylesheet" href="styles/site.css" type="text/css" />
  6. <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7. </head>
  8. <body class="theme-default aui-theme-default">
  9. <div id="page">
  10. <div id="main" class="aui-page-panel">
  11. <div id="main-header">
  12. <div id="breadcrumb-section">
  13. <ol id="breadcrumbs">
  14. <li class="first">
  15. <span><a href="index.html">Asterisk Project</a></span>
  16. </li>
  17. <li>
  18. <span><a href="Asterisk-13-Command-Reference_29394274.html">Asterisk 13 Command Reference</a></span>
  19. </li>
  20. <li>
  21. <span><a href="Asterisk-13-Dialplan-Functions_29394287.html">Asterisk 13 Dialplan Functions</a></span>
  22. </li>
  23. </ol>
  24. </div>
  25. <h1 id="title-heading" class="pagetitle">
  26. <span id="title-text">
  27. Asterisk Project : Asterisk 13 Function_FILE
  28. </span>
  29. </h1>
  30. </div>
  31. <div id="content" class="view">
  32. <div class="page-metadata">
  33. Created by <span class='author'> wikibot</span> on Aug 08, 2014
  34. </div>
  35. <div id="main-content" class="wiki-content group">
  36. <h1 id="Asterisk13Function_FILE-FILE()">FILE()</h1>
  37. <h3 id="Asterisk13Function_FILE-Synopsis">Synopsis</h3>
  38. <p>Read or write text file.</p>
  39. <h3 id="Asterisk13Function_FILE-Description">Description</h3>
  40. <p>Read and write text file in character and line mode.</p>
  41. <p>Examples:</p>
  42. <p>Read mode (byte):</p>
  43. <p>;reads the entire content of the file.</p>
  44. <p>Set(foo=${FILE(/tmp/test.txt)})</p>
  45. <p>;reads from the 11th byte to the end of the file (i.e. skips the first 10).</p>
  46. <p>Set(foo=${FILE(/tmp/test.txt,10)})</p>
  47. <p>;reads from the 11th to 20th byte in the file (i.e. skip the first 10, then read 10 bytes).</p>
  48. <p>Set(foo=${FILE(/tmp/test.txt,10,10)})</p>
  49. <p>Read mode (line):</p>
  50. <p>; reads the 3rd line of the file.</p>
  51. <p>Set(foo=${FILE(/tmp/test.txt,3,1,l)})</p>
  52. <p>; reads the 3rd and 4th lines of the file.</p>
  53. <p>Set(foo=${FILE(/tmp/test.txt,3,2,l)})</p>
  54. <p>; reads from the third line to the end of the file.</p>
  55. <p>Set(foo=${FILE(/tmp/test.txt,3,,l)})</p>
  56. <p>; reads the last three lines of the file.</p>
  57. <p>Set(foo=${FILE(/tmp/test.txt,-3,,l)})</p>
  58. <p>; reads the 3rd line of a DOS-formatted file.</p>
  59. <p>Set(foo=${FILE(/tmp/test.txt,3,1,l,d)})</p>
  60. <p>Write mode (byte):</p>
  61. <p>; truncate the file and write &quot;bar&quot;</p>
  62. <p>Set(FILE(/tmp/test.txt)=bar)</p>
  63. <p>; Append &quot;bar&quot;</p>
  64. <p>Set(FILE(/tmp/test.txt,,,a)=bar)</p>
  65. <p>; Replace the first byte with &quot;bar&quot; (replaces 1 character with 3)</p>
  66. <p>Set(FILE(/tmp/test.txt,0,1)=bar)</p>
  67. <p>; Replace 10 bytes beginning at the 21st byte of the file with &quot;bar&quot;</p>
  68. <p>Set(FILE(/tmp/test.txt,20,10)=bar)</p>
  69. <p>; Replace all bytes from the 21st with &quot;bar&quot;</p>
  70. <p>Set(FILE(/tmp/test.txt,20)=bar)</p>
  71. <p>; Insert &quot;bar&quot; after the 4th character</p>
  72. <p>Set(FILE(/tmp/test.txt,4,0)=bar)</p>
  73. <p>Write mode (line):</p>
  74. <p>; Replace the first line of the file with &quot;bar&quot;</p>
  75. <p>Set(FILE(/tmp/foo.txt,0,1,l)=bar)</p>
  76. <p>; Replace the last line of the file with &quot;bar&quot;</p>
  77. <p>Set(FILE(/tmp/foo.txt,-1,,l)=bar)</p>
  78. <p>; Append &quot;bar&quot; to the file with a newline</p>
  79. <p>Set(FILE(/tmp/foo.txt,,,al)=bar)</p>
  80. <div class="aui-message hint shadowed information-macro">
  81. <p class="title">Note</p>
  82. <span class="aui-icon icon-hint">Icon</span>
  83. <div class="message-content">
  84. <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>
  85. </div>
  86. </div>
  87. <h3 id="Asterisk13Function_FILE-Syntax">Syntax</h3>
  88. <div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent">
  89. <pre>FILE(filename,offset,length,options,format)</pre>
  90. </div></div>
  91. <h5 id="Asterisk13Function_FILE-Arguments">Arguments</h5>
  92. <ul>
  93. <li><code>filename</code></li>
  94. <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>
  95. <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>
  96. <li><code>options</code>
  97. <ul>
  98. <li><code>l</code> - Line mode: offset and length are assumed to be measured in lines, instead of byte offsets.</li>
  99. <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>
  100. <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>
  101. </ul>
  102. </li>
  103. <li><code>format</code> - The <em>format</em> parameter may be used to delimit the type of line terminators in line mode.
  104. <ul>
  105. <li><code>u</code> - Unix newline format.</li>
  106. <li><code>d</code> - DOS newline format.</li>
  107. <li><code>m</code> - Macintosh newline format.</li>
  108. </ul>
  109. </li>
  110. </ul>
  111. <h3 id="Asterisk13Function_FILE-SeeAlso">See Also</h3>
  112. <ul>
  113. <li><a href="Asterisk-13-Function_FILE_COUNT_LINE_29394642.html">Asterisk 13 Function_FILE_COUNT_LINE</a></li>
  114. <li><a href="Asterisk-13-Function_FILE_FORMAT_29394643.html">Asterisk 13 Function_FILE_FORMAT</a></li>
  115. </ul>
  116. <h3 id="Asterisk13Function_FILE-ImportVersion">Import Version</h3>
  117. <p>This documentation was imported from Asterisk Version SVN-branch-13-r420538</p>
  118. </div>
  119. </div> </div>
  120. <div id="footer">
  121. <section class="footer-body">
  122. <p>Document generated by Confluence on Aug 11, 2014 13:46</p>
  123. </section>
  124. </div>
  125. </div> </body>
  126. </html>