<?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 => 'ja',
  ),
  'this' => 
  array (
    0 => 'function.scandir.php',
    1 => 'scandir',
    2 => '指定されたパスのファイルとディレクトリのリストを取得する',
  ),
  'up' => 
  array (
    0 => 'ref.dir.php',
    1 => 'ディレクトリ 関数',
  ),
  'prev' => 
  array (
    0 => 'function.rewinddir.php',
    1 => 'rewinddir',
  ),
  'next' => 
  array (
    0 => 'book.fileinfo.php',
    1 => 'Fileinfo',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    '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">
   指定されたパスのファイルとディレクトリのリストを取得する
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.scandir-description">
  <h3 class="title">説明</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">
   <code class="parameter">directory</code> 内のファイルおよびディレクトリを
   配列で返します。
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.scandir-parameters">
  <h3 class="title">パラメータ</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">directory</code></dt>
     <dd>
      <p class="para">
       調べるディレクトリ。
      </p>
     </dd>
    
    
     <dt><code class="parameter">sorting_order</code></dt>
     <dd>
      <p class="para">
       デフォルトでは、ソート順はアルファベット昇順です。
       オプションの <code class="parameter">sorting_order</code>
       に <strong><code><a href="dir.constants.php#constant.scandir-sort-descending">SCANDIR_SORT_DESCENDING</a></code></strong> を設定した場合、
       ソート順はアルファベット降順になります。
       <strong><code><a href="dir.constants.php#constant.scandir-sort-none">SCANDIR_SORT_NONE</a></code></strong> を設定すると、
       結果をソートせずに返します。
      </p>
     </dd>
    
    
     <dt><code class="parameter">context</code></dt>
     <dd>
      <p class="para">
       <code class="parameter">context</code> パラメータの説明については、
       マニュアルの<a href="ref.stream.php" class="link">ストリーム</a>
       を参照ください。
      </p> 
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.scandir-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   成功した場合にファイル名の配列、失敗した場合に <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> を返します。
   <code class="parameter">directory</code> がディレクトリではない場合は、
   <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> を返し、<strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> レベルのエラーを
   発行します。
  </p> 
 </div>


 <div class="refsect1 changelog" id="refsect1-function.scandir-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">context</code> は、nullable になりました。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>



 <div class="refsect1 examples" id="refsect1-function.scandir-examples">
  <h3 class="title">例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>例1 <span class="function"><strong>scandir()</strong></span> の簡単な例</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>上の例の出力は、
たとえば以下のようになります。</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">注意</h3>
  <div class="tip"><strong class="tip">ヒント</strong><p class="simpara"><a href="filesystem.configuration.php#ini.allow-url-fopen" class="link">fopen wrappers</a> が有効の場合、この関数のファイル名として
URL を使用することができます。ファイル名の指定方法に関する詳細は
<span class="function"><a href="function.fopen.php" class="function">fopen()</a></span> を参照ください。
<a href="wrappers.php" class="xref">サポートするプロトコル/ラッパー</a> には、さまざまなラッパーの機能やその使用法、
提供される定義済み変数などの情報がまとめられています。</p></div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.scandir-seealso">
  <h3 class="title">参考</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.opendir.php" class="function" rel="rdfs-seeAlso">opendir()</a> - ディレクトリハンドルをオープンする</span></li>
    <li><span class="function"><a href="function.readdir.php" class="function" rel="rdfs-seeAlso">readdir()</a> - ディレクトリハンドルからエントリを読み込む</span></li>
    <li><span class="function"><a href="function.glob.php" class="function" rel="rdfs-seeAlso">glob()</a> - パターンにマッチするパス名を探す</span></li>
    <li><span class="function"><a href="function.is-dir.php" class="function" rel="rdfs-seeAlso">is_dir()</a> - ファイルがディレクトリかどうかを調べる</span></li>
    <li><span class="function"><a href="function.sort.php" class="function" rel="rdfs-seeAlso">sort()</a> - 配列を昇順にソートする</span></li>
   </ul>
  </p>
 </div>

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