2010-03-28 22:10:10 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 06:49:33 +00:00
|
|
|
<!-- $Revision$ -->
|
2002-04-15 00:12:54 +00:00
|
|
|
<!-- splitted from ./en/functions/dir.xml, last change in rev 1.2 -->
|
2007-06-20 22:25:43 +00:00
|
|
|
<refentry xml:id="function.readdir" xmlns="http://docbook.org/ns/docbook">
|
2005-04-11 22:04:40 +00:00
|
|
|
<refnamediv>
|
|
|
|
<refname>readdir</refname>
|
|
|
|
<refpurpose>Read entry from directory handle</refpurpose>
|
|
|
|
</refnamediv>
|
2005-04-11 23:28:21 +00:00
|
|
|
|
|
|
|
<refsect1 role="description">
|
2005-04-11 22:04:40 +00:00
|
|
|
&reftitle.description;
|
|
|
|
<methodsynopsis>
|
|
|
|
<type>string</type><methodname>readdir</methodname>
|
2008-08-08 18:44:17 +00:00
|
|
|
<methodparam choice="opt"><type>resource</type><parameter>dir_handle</parameter></methodparam>
|
2005-04-11 22:04:40 +00:00
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
|
|
|
Returns the filename of the next file from the directory. The
|
|
|
|
filenames are returned in the order in which they are stored by
|
|
|
|
the filesystem.
|
|
|
|
</para>
|
2005-04-11 23:28:21 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
2005-04-11 22:04:40 +00:00
|
|
|
<para>
|
2005-04-11 23:28:21 +00:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>dir_handle</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The directory handle <type>resource</type> previously opened
|
2008-08-08 18:44:17 +00:00
|
|
|
with <function>opendir</function>. If the directory handle is
|
|
|
|
not specified, the last link opened by <function>opendir</function>
|
|
|
|
is assumed.
|
2005-04-11 23:28:21 +00:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
2005-04-11 22:04:40 +00:00
|
|
|
</para>
|
2005-04-11 23:28:21 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="returnvalues">
|
|
|
|
&reftitle.returnvalues;
|
|
|
|
<para>
|
2009-11-09 10:26:08 +00:00
|
|
|
Returns the filename on success&return.falseforfailure;.
|
2005-04-11 23:28:21 +00:00
|
|
|
</para>
|
2007-04-07 23:34:30 +00:00
|
|
|
&return.falseproblem;
|
2005-04-11 23:28:21 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
2005-04-11 22:04:40 +00:00
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title>List all files in a directory</title>
|
2005-04-11 23:28:21 +00:00
|
|
|
<para>
|
|
|
|
Please note the fashion in which <function>readdir</function>'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 <link
|
|
|
|
linkend="language.operators.comparison">Comparison
|
|
|
|
Operators</link> for more information) &false; since otherwise,
|
|
|
|
any directory entry whose name evaluates to &false; will stop the
|
|
|
|
loop (e.g. a directory named "0").
|
|
|
|
</para>
|
2005-04-11 22:04:40 +00:00
|
|
|
<programlisting role="php">
|
2002-04-15 00:12:54 +00:00
|
|
|
<![CDATA[
|
|
|
|
<?php
|
2003-07-16 17:25:02 +00:00
|
|
|
|
2002-04-15 00:12:54 +00:00
|
|
|
if ($handle = opendir('/path/to/files')) {
|
|
|
|
echo "Directory handle: $handle\n";
|
|
|
|
echo "Files:\n";
|
|
|
|
|
|
|
|
/* This is the correct way to loop over the directory. */
|
2005-04-11 22:04:40 +00:00
|
|
|
while (false !== ($file = readdir($handle))) {
|
2002-04-15 00:12:54 +00:00
|
|
|
echo "$file\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the WRONG way to loop over the directory. */
|
2005-04-11 22:04:40 +00:00
|
|
|
while ($file = readdir($handle)) {
|
2002-04-15 00:12:54 +00:00
|
|
|
echo "$file\n";
|
|
|
|
}
|
|
|
|
|
2005-04-11 22:04:40 +00:00
|
|
|
closedir($handle);
|
2002-04-15 00:12:54 +00:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
]]>
|
2005-04-11 22:04:40 +00:00
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title>
|
|
|
|
List all files in the current directory and strip out <literal>.</literal>
|
|
|
|
and <literal>..</literal>
|
|
|
|
</title>
|
|
|
|
<programlisting role="php">
|
2002-04-15 00:12:54 +00:00
|
|
|
<![CDATA[
|
2005-04-11 22:04:40 +00:00
|
|
|
<?php
|
2002-04-15 00:12:54 +00:00
|
|
|
if ($handle = opendir('.')) {
|
2005-04-11 22:04:40 +00:00
|
|
|
while (false !== ($file = readdir($handle))) {
|
|
|
|
if ($file != "." && $file != "..") {
|
|
|
|
echo "$file\n";
|
|
|
|
}
|
2002-04-15 00:12:54 +00:00
|
|
|
}
|
2005-04-11 22:04:40 +00:00
|
|
|
closedir($handle);
|
2002-04-15 00:12:54 +00:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
]]>
|
2005-04-11 22:04:40 +00:00
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
2005-04-11 23:28:21 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
2005-04-11 22:04:40 +00:00
|
|
|
<para>
|
2005-04-11 23:28:21 +00:00
|
|
|
<simplelist>
|
|
|
|
<member><function>is_dir</function></member>
|
|
|
|
<member><function>glob</function></member>
|
2008-11-06 20:44:12 +00:00
|
|
|
<member><function>opendir</function></member>
|
|
|
|
<member><function>scandir</function></member>
|
2005-04-11 23:28:21 +00:00
|
|
|
</simplelist>
|
2005-04-11 22:04:40 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
2002-04-15 00:12:54 +00:00
|
|
|
|
|
|
|
<!-- 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
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2002-04-15 00:12:54 +00:00
|
|
|
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
|
|
|
|
-->
|