<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.dir.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.readdir.php',
    1 => 'readdir',
    2 => 'Read entry from directory handle',
  ),
  'up' => 
  array (
    0 => 'ref.dir.php',
    1 => 'Функції для роботи з теками',
  ),
  'prev' => 
  array (
    0 => 'function.opendir.php',
    1 => 'opendir',
  ),
  'next' => 
  array (
    0 => 'function.rewinddir.php',
    1 => 'rewinddir',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/dir/functions/readdir.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.readdir" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">readdir</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">readdir</span> &mdash; <span class="dc-title">Read entry from directory handle</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.readdir-description">
  <h3 class="title">Опис</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>readdir</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span></span> <code class="parameter">$dir_handle</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><span class="type"><a href="language.types.string.php" class="type string">string</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   Returns the name of the next entry in the directory. The
   entries are returned in the order in which they are stored by
   the filesystem.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.readdir-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">dir_handle</code></dt>
     <dd>
      <p class="para">
       The directory handle <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> previously opened
       with <span class="function"><a href="function.opendir.php" class="function">opendir()</a></span>. If the directory handle is 
       not specified, the last link opened by <span class="function"><a href="function.opendir.php" class="function">opendir()</a></span> 
       is assumed.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.readdir-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns the entry name on success або <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> в разі помилки.
  </p> 
  <div class="warning"><strong class="warning">Увага</strong><p class="simpara">Ця функція може
повертати як логічне <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, так і не логічне значення, яке прирівнюється до
<strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>. Докладніше про це описано в розділі <a href="language.types.boolean.php" class="link">Логічні типи даних</a>. Для перевірки
значення, яке повертає ця функція, використовується <a href="language.operators.comparison.php" class="link">оператор ===</a>.</p></div>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.readdir-changelog">
  <h3 class="title">Журнал змін</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Версія</th>
      <th>Опис</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">dir_handle</code> is now nullable.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.readdir-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Приклад #1 List all entries in a directory</strong></p>
    <div class="example-contents"><p>
     Please note the fashion in which <span class="function"><strong>readdir()</strong></span>&#039;s
     return value is checked in the examples below. We are explicitly
     testing whether the return value is identical to (equal to and of
     the same type as--see <a href="language.operators.comparison.php" class="link">Comparison
     Operators</a> for more information) <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> since otherwise,
     any directory entry whose name evaluates to <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> will stop the
     loop (e.g. a directory named &quot;0&quot;).
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$handle </span><span style="color: #007700">= </span><span style="color: #0000BB">opendir</span><span style="color: #007700">(</span><span style="color: #DD0000">'/path/to/files'</span><span style="color: #007700">)) {<br />    echo </span><span style="color: #DD0000">"Directory handle: </span><span style="color: #0000BB">$handle</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />    echo </span><span style="color: #DD0000">"Entries:\n"</span><span style="color: #007700">;<br /><br />    </span><span style="color: #FF8000">/* This is the correct way to loop over the directory. */<br />    </span><span style="color: #007700">while (</span><span style="color: #0000BB">false </span><span style="color: #007700">!== (</span><span style="color: #0000BB">$entry </span><span style="color: #007700">= </span><span style="color: #0000BB">readdir</span><span style="color: #007700">(</span><span style="color: #0000BB">$handle</span><span style="color: #007700">))) {<br />        echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$entry</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />    }<br /><br />    </span><span style="color: #FF8000">/* This is the WRONG way to loop over the directory. */<br />    </span><span style="color: #007700">while (</span><span style="color: #0000BB">$entry </span><span style="color: #007700">= </span><span style="color: #0000BB">readdir</span><span style="color: #007700">(</span><span style="color: #0000BB">$handle</span><span style="color: #007700">)) {<br />        echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$entry</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />    }<br /><br />    </span><span style="color: #0000BB">closedir</span><span style="color: #007700">(</span><span style="color: #0000BB">$handle</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Приклад #2 
     List all entries in the current directory and strip out <code class="literal">.</code>
     and <code class="literal">..</code>
    </strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$handle </span><span style="color: #007700">= </span><span style="color: #0000BB">opendir</span><span style="color: #007700">(</span><span style="color: #DD0000">'.'</span><span style="color: #007700">)) {<br />    while (</span><span style="color: #0000BB">false </span><span style="color: #007700">!== (</span><span style="color: #0000BB">$entry </span><span style="color: #007700">= </span><span style="color: #0000BB">readdir</span><span style="color: #007700">(</span><span style="color: #0000BB">$handle</span><span style="color: #007700">))) {<br />        if (</span><span style="color: #0000BB">$entry </span><span style="color: #007700">!= </span><span style="color: #DD0000">"." </span><span style="color: #007700">&amp;&amp; </span><span style="color: #0000BB">$entry </span><span style="color: #007700">!= </span><span style="color: #DD0000">".."</span><span style="color: #007700">) {<br />            echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$entry</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />        }<br />    }<br />    </span><span style="color: #0000BB">closedir</span><span style="color: #007700">(</span><span style="color: #0000BB">$handle</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.readdir-seealso">
  <h3 class="title">Прогляньте також</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.is-dir.php" class="function" rel="rdfs-seeAlso">is_dir()</a> - Tells whether the filename is a directory</span></li>
    <li><span class="function"><a href="function.glob.php" class="function" rel="rdfs-seeAlso">glob()</a> - Find pathnames matching a pattern</span></li>
    <li><span class="function"><a href="function.opendir.php" class="function" rel="rdfs-seeAlso">opendir()</a> - Open directory handle</span></li>
    <li><span class="function"><a href="function.scandir.php" class="function" rel="rdfs-seeAlso">scandir()</a> - List files and directories inside the specified path</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>