<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.scandir.php',
    1 => 'scandir',
    2 => 'List files and directories inside the specified path',
  ),
  'up' => 
  array (
    0 => 'ref.dir.php',
    1 => 'Directory Functions',
  ),
  'prev' => 
  array (
    0 => 'function.rewinddir.php',
    1 => 'rewinddir',
  ),
  'next' => 
  array (
    0 => 'book.fileinfo.php',
    1 => 'Fileinfo',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/dir/functions/scandir.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.scandir" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">scandir</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">scandir</span> &mdash; <span class="dc-title">List files and directories inside the specified path</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.scandir-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>scandir</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$directory</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$sorting_order</code><span class="initializer"> = <strong><code><a href="dir.constants.php#constant.scandir-sort-ascending">SCANDIR_SORT_ASCENDING</a></code></strong></span></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">$context</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.array.php" class="type array">array</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 an <span class="type"><a href="language.types.array.php" class="type array">array</a></span> of files and directories from the
   <code class="parameter">directory</code>.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.scandir-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">directory</code></dt>
     <dd>
      <p class="para">
       The directory that will be scanned.
      </p>
     </dd>
    
    
     <dt><code class="parameter">sorting_order</code></dt>
     <dd>
      <p class="para">
       By default, the sorted order is alphabetical in ascending order.  If
       the optional <code class="parameter">sorting_order</code> is set to
       <strong><code><a href="dir.constants.php#constant.scandir-sort-descending">SCANDIR_SORT_DESCENDING</a></code></strong>, then the sort order is
       alphabetical in descending order. If it is set to
       <strong><code><a href="dir.constants.php#constant.scandir-sort-none">SCANDIR_SORT_NONE</a></code></strong> then the result is unsorted.
      </p>
     </dd>
    
    
     <dt><code class="parameter">context</code></dt>
     <dd>
      <p class="para">
       For a description of the <code class="parameter">context</code> parameter, 
       refer to <a href="ref.stream.php" class="link">the streams section</a> of
       the manual.
      </p> 
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.scandir-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns an <span class="type"><a href="language.types.array.php" class="type array">array</a></span> of filenames on success, or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on 
   failure. If <code class="parameter">directory</code> is not a directory, then 
   boolean <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> is returned, and an error of level 
   <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> is generated.
  </p> 
 </div>


 <div class="refsect1 changelog" id="refsect1-function.scandir-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

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

    </tbody>
   
  </table>

 </div>



 <div class="refsect1 examples" id="refsect1-function.scandir-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 A simple <span class="function"><strong>scandir()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$dir    </span><span style="color: #007700">= </span><span style="color: #DD0000">'/tmp'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$files1 </span><span style="color: #007700">= </span><span style="color: #0000BB">scandir</span><span style="color: #007700">(</span><span style="color: #0000BB">$dir</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$files2 </span><span style="color: #007700">= </span><span style="color: #0000BB">scandir</span><span style="color: #007700">(</span><span style="color: #0000BB">$dir</span><span style="color: #007700">, </span><span style="color: #0000BB">SCANDIR_SORT_DESCENDING</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$files1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$files2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output
something similar to:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Array
(
    [0] =&gt; .
    [1] =&gt; ..
    [2] =&gt; bar.php
    [3] =&gt; foo.txt
    [4] =&gt; somedir
)
Array
(
    [0] =&gt; somedir
    [1] =&gt; foo.txt
    [2] =&gt; bar.php
    [3] =&gt; ..
    [4] =&gt; .
)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.scandir-notes">
  <h3 class="title">Notes</h3>
  <div class="tip"><strong class="tip">Tip</strong><p class="simpara">A URL can be used as a
filename with this function if the <a href="filesystem.configuration.php#ini.allow-url-fopen" class="link">fopen wrappers</a> have been enabled.
See <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span> for more details on how to specify the
filename. See the <a href="wrappers.php" class="xref">Supported Protocols and Wrappers</a> for links to information
about what abilities the various wrappers have, notes on their usage,
and information on any predefined variables they may
provide.</p></div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.scandir-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <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.readdir.php" class="function" rel="rdfs-seeAlso">readdir()</a> - Read entry from directory handle</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.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.sort.php" class="function" rel="rdfs-seeAlso">sort()</a> - Sort an array in ascending order</span></li>
   </ul>
  </p>
 </div>

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