1
0
mirror of https://github.com/php/doc-ja.git synced 2026-04-28 18:43:16 +02:00
Files
archived-doc-ja/reference/dir/functions/opendir.xml
T
Yoshinari Takaoka 192c33c285 Rework documentation for dir functions
Include 8.5 deprecation for passing null to use the last opened directory.

https://github.com/php/doc-en/commit/5c7e9e1351240b5f9e0858cdeba8f754a366d1b7
2025-11-30 00:11:24 +09:00

175 lines
5.0 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 5c7e9e1351240b5f9e0858cdeba8f754a366d1b7 Maintainer: mumumu Status: ready -->
<refentry xml:id="function.opendir" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>opendir</refname>
<refpurpose>ディレクトリハンドルをオープンする</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type class="union"><type>resource</type><type>false</type></type><methodname>opendir</methodname>
<methodparam><type>string</type><parameter>directory</parameter></methodparam>
<methodparam choice="opt"><type class="union"><type>resource</type><type>null</type></type><parameter>context</parameter><initializer>&null;</initializer></methodparam>
</methodsynopsis>
<simpara>
ディレクトリハンドルをオープンします。このハンドルは、この後
<function>closedir</function>, <function>readdir</function>,
<function>rewinddir</function> 関数コールで使用されます。
</simpara>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>directory</parameter></term>
<listitem>
<simpara>
オープンするディレクトリのパス。
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>context</parameter></term>
<listitem>
<simpara>
<parameter>context</parameter> パラメータの詳細については
マニュアルの<link linkend="ref.stream">ストリーム</link>
を参照ください。
</simpara>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<simpara>
成功した場合にディレクトリハンドルを返します。
&return.falseforfailure;
</simpara>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
&fs.emits.warning.on.failure;
<simpara>
<parameter>directory</parameter> が有効なディレクトリでない場合、
権限の制限によりディレクトリがオープンできない場合、
またはファイルシステムのエラー時に起こりえます。
</simpara>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.0.0</entry>
<entry>
<parameter>context</parameter> は、nullable になりました。
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title>
ディレクトリ中の全てのエントリを表示します。
ただし、特別な <literal>.</literal>
<literal>..</literal> ディレクトリはスキップします。
</title>
<simpara>
ファイル名やディレクトリ名は、
PHP が &false; と見なす文字列
(例: <literal>"0"</literal> という名前のディレクトリ)
の可能性があり、かつ <function>readdir</function>
は全てのディレクトリエントリを読み取ったあとに &false; を返します。
そのため、PHP が &false;
とみなすディレクトリ名と、
全てのディレクトリエントリを読み取ったことを適切に区別するためには、
<link linkend="language.operators.comparison">比較演算子</link> <literal>===</literal>
を使う必要があります。
</simpara>
<programlisting role="php">
<![CDATA[
<?php
if ($handle = opendir('/path/to/files')) {
echo "Entries:\n";
/* Correctly handling directory entries that may be considered falsy */
while (false !== ($entry = readdir($handle))) {
if ($entry === '.' || $entry === '..') {
continue;
}
echo "$entry\n";
}
closedir($handle);
}
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Entries:
base
en
fr
output.md
test.php
]]>
</screen>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><function>readdir</function></member>
<member><function>rewinddir</function></member>
<member><function>closedir</function></member>
<member><function>dir</function></member>
<member><function>is_dir</function></member>
<member><function>glob</function></member>
<member><function>scandir</function></member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->