php-doc-en/functions/dir.xml
1999-12-11 00:42:09 +00:00

188 lines
5.2 KiB
XML

<reference id="ref.dir">
<title>Directory functions</title>
<titleabbrev>Directories</titleabbrev>
<refentry id="function.chdir">
<refnamediv>
<refname>chdir</refname>
<refpurpose>change directory</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>chdir</function></funcdef>
<paramdef>string <parameter>directory</parameter></paramdef>
</funcsynopsis>
<para>
Changes PHP's current directory to
<parameter>directory</parameter>. Returns FALSE if unable to
change directory, TRUE otherwise.
</para>
</refsect1>
</refentry>
<refentry id="class.dir">
<refnamediv>
<refname>dir</refname>
<refpurpose>directory class</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>new <function>dir</function></funcdef>
<paramdef>string <parameter>directory</parameter></paramdef>
</funcsynopsis>
<para>
A pseudo-object oriented mechanism for reading a directory. The
given <parameter>directory</parameter> is opened. Two properties
are available once directory has been opened. The handle
property can be used with other directory functions such as
<function>readdir</function>, <function>rewinddir</function> and
<function>closedir</function>. The path property is set to path
the directory that was opened. Three methods are available:
read, rewind and close.
<example>
<title><function>Dir</function> Example</title>
<programlisting role="php">
$d = dir("/etc");
echo "Handle: ".$d->handle."&lt;br>\n";
echo "Path: ".$d->path."&lt;br>\n";
while($entry=$d->read()) {
echo $entry."&lt;br>\n";
}
$d->close();
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.closedir">
<refnamediv>
<refname>closedir</refname>
<refpurpose>close directory handle</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>void <function>closedir</function></funcdef>
<paramdef>int <parameter>dir_handle</parameter></paramdef>
</funcsynopsis>
<para>
Closes the directory stream indicated by
<parameter>dir_handle</parameter>. The stream must have previously
been opened by <function>opendir</function>.
</para>
</refsect1>
</refentry>
<refentry id="function.opendir">
<refnamediv>
<refname>opendir</refname>
<refpurpose>open directory handle</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>opendir</function></funcdef>
<paramdef>string <parameter>path</parameter></paramdef>
</funcsynopsis>
<para>
Returns a directory handle to be used in subsequent
<function>closedir</function>, <function>readdir</function>, and
<function>rewinddir</function> calls.
</para>
</refsect1>
</refentry>
<refentry id="function.readdir">
<refnamediv>
<refname>readdir</refname>
<refpurpose>read entry from directory handle</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>string <function>readdir</function></funcdef>
<paramdef>int <parameter>dir_handle</parameter></paramdef>
</funcsynopsis>
<para>
Returns the filename of the next file from the directory. The
filenames are not returned in any particular order.
<example>
<title>List all files in the current directory</title>
<programlisting role="php">
&lt;?php
$handle=opendir('.');
echo "Directory handle: $handle\n";
echo "Files:\n";
while ($file = readdir($handle)) {
echo "$file\n";
}
closedir($handle);
?&gt;
</programlisting>
</example>
</para>
<para>
Note that <function>readdir</function> will return the . and
.. entries. If you don't want these, simply strip them out:
<example>
<title>
List all files in the current directory and strip out . and
..
</title>
<programlisting role="php">
&lt;?php
$handle=opendir('.');
while ($file = readdir($handle)) {
if ($file != "." && $file != "..") {
echo "$file\n";
}
}
closedir($handle);
?&gt;
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<refentry id="function.rewinddir">
<refnamediv>
<refname>rewinddir</refname>
<refpurpose>rewind directory handle</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>void <function>rewinddir</function></funcdef>
<paramdef>int <parameter>dir_handle</parameter></paramdef>
</funcsynopsis>
<para>
Resets the directory stream indicated by
<parameter>dir_handle</parameter> to the beginning of the
directory.
</para>
</refsect1>
</refentry>
</reference>
<!-- 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
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->