<HTML ><HEAD ><TITLE >dir</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Directory functions" HREF="ref.dir.html"><LINK REL="PREVIOUS" TITLE="chroot" HREF="function.chroot.html"><LINK REL="NEXT" TITLE="closedir" HREF="function.closedir.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.chroot.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.closedir.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="class.dir" ></A >dir</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN19949" ></A >dir -- directory class</DIV ><DIV CLASS="refsect1" ><A NAME="AEN19952" ></A ><H2 >Description</H2 ><pre class="classsynopsis" > <SPAN class="ooclass" >class <span class="classname" >dir </span ></SPAN >{ <code class="constructorsynopsis" > dir(<span class="methodparam" ><span class="type" >string </span ><span class="parameter" >directory</span ></span >); </code ><code class="fieldsynopsis" > <span class="type" >string </span ><span class="varname" >path</span >; </code ><code class="fieldsynopsis" > <span class="type" >resource </span ><span class="varname" >handle</span >; </code ><code class="methodsynopsis" > <span class="type" >string </span >read(); </code ><code class="methodsynopsis" > <span class="type" >void </span >rewind(); </code ><code class="methodsynopsis" > <span class="type" >void </span >close(); </code >}</pre ><P > A pseudo-object oriented mechanism for reading a directory. The given <TT CLASS="parameter" ><I >directory</I ></TT > is opened. Two properties are available once the directory has been opened. The handle property can be used with other directory functions such as <A HREF="function.readdir.html" ><B CLASS="function" >readdir()</B ></A >, <A HREF="function.rewinddir.html" ><B CLASS="function" >rewinddir()</B ></A > and <A HREF="function.closedir.html" ><B CLASS="function" >closedir()</B ></A >. The path property is set to path the directory that was opened. Three methods are available: read, rewind and close. </P ><P > Please note the fashion in which <B CLASS="function" >dir()</B >'s return value is checked in the example below. We are explicitly testing whether the return value is identical to (equal to and of the same type as--see <A HREF="language.operators.comparison.html" > Comparison Operators</A > for more information) <TT CLASS="constant" ><B >FALSE</B ></TT > since otherwise, any directory entry whose name evaluates to <TT CLASS="constant" ><B >FALSE</B ></TT > will stop the loop. <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN19990" ></A ><P ><B >Example 1. <B CLASS="function" >dir()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >$d = dir("/etc"); echo "Handle: ".$d->handle."<br>\n"; echo "Path: ".$d->path."<br>\n"; while (false !== ($entry = $d->read())) { echo $entry."<br>\n"; } $d->close();</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > The order in which directory entries are returned by the read method is system-dependent. </P ></BLOCKQUOTE ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > This defines the internal class <B CLASS="classname" >Directory</B >, meaning that you will not be able to define your own classes with that name. For a full list of predefined classes in PHP, please see <A HREF="reserved.classes.html" >Predefined Classes</A >. </P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.chroot.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.closedir.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >chroot</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.dir.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >closedir</TD ></TR ></TABLE ></DIV ></BODY ></HTML >