Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > by-pkgid > 703d980c580707c382b4e43e25965bc5 > files > 9352

php-manual-pt_BR-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>readdir</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="Manual do PHP"
HREF="index.html"><LINK
REL="UP"
TITLE="Diretórios"
HREF="ref.dir.html"><LINK
REL="PREVIOUS"
TITLE="opendir"
HREF="function.opendir.html"><LINK
REL="NEXT"
TITLE="rewinddir"
HREF="function.rewinddir.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=UTF-8"></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"
>Manual do PHP</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.opendir.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.rewinddir.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.readdir"
></A
>readdir</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN33628"
></A
><P
>    (PHP 3, PHP 4, PHP 5)</P
>readdir&nbsp;--&nbsp;Lê os campos do manipulador do diretório</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN33631"
></A
><H2
>Descrição</H2
>string <B
CLASS="methodname"
>readdir</B
> ( resource dir_handle )<BR
></BR
><P
>&#13;     Retorna o nome de arquivo do próximo arquivo do diretório. Os
     nomes de arquivos são retornados na ordem informada pelo
     sistema de arquivos.
    </P
><P
>&#13;     Verifique cuidadosamente o estilo de checagem dos valores retornados
     por <B
CLASS="function"
>readdir()</B
> nos exemplos abaixo. Nós explicitamente
     testamos se o valor retornado é idêntico a (igual e
     do mesmo tipo que <TT
CLASS="constant"
><B
>FALSE</B
></TT
> --- veja <A
HREF="language.operators.comparison.html"
>Operadores de
     Comparação</A
> para maiores detalhes). De outra forma,
     qualquer entrada de diretório que seja avaliada para <TT
CLASS="constant"
><B
>FALSE</B
></TT
> irá parar o
     loop (por exemplo, um diretório nomeado "0").
    </P
><P
>&#13;     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN33646"
></A
><P
><B
>Exemplo 1. Lista todos os arquivos em um diretório</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#FF8000">// Note que !== não existia antes do PHP 4.0.0-RC2<br /><br /></font><font color="#007700">if (</font><font color="#0000BB">$handle </font><font color="#007700">= </font><font color="#0000BB">opendir</font><font color="#007700">(</font><font color="#DD0000">'/path/to/files'</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"Manipulador de diretório: $handle</font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"Arquivos:\n"</font><font color="#007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">/* Esta é a forma correta de varrer o diretório */<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">while (</font><font color="#0000BB">false </font><font color="#007700">!== (</font><font color="#0000BB">$file </font><font color="#007700">= </font><font color="#0000BB">readdir</font><font color="#007700">(</font><font color="#0000BB">$handle</font><font color="#007700">))) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"$file</font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#FF8000">/* Esta é a forma INCORRETA de varrer o diretório */<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#007700">while (</font><font color="#0000BB">$file </font><font color="#007700">= </font><font color="#0000BB">readdir</font><font color="#007700">(</font><font color="#0000BB">$handle</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"$file</font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">closedir</font><font color="#007700">(</font><font color="#0000BB">$handle</font><font color="#007700">);<br />}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     Note que <B
CLASS="function"
>readdir()</B
> irá retornar o <TT
CLASS="literal"
>.</TT
>
     e
     <TT
CLASS="literal"
>..</TT
> . Se você não quer estes simplesmente
     os retire:
     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN33653"
></A
><P
><B
>Exemplo 2. 
       Listar todos os arquivos no diretório atual e retirar <TT
CLASS="literal"
>.</TT
>
       e <TT
CLASS="literal"
>..</TT
>
      </B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br /></font><font color="#007700">if (</font><font color="#0000BB">$handle </font><font color="#007700">= </font><font color="#0000BB">opendir</font><font color="#007700">(</font><font color="#DD0000">'.'</font><font color="#007700">)) {<br />&nbsp;&nbsp;&nbsp;&nbsp;while (</font><font color="#0000BB">false </font><font color="#007700">!== (</font><font color="#0000BB">$file </font><font color="#007700">= </font><font color="#0000BB">readdir</font><font color="#007700">(</font><font color="#0000BB">$handle</font><font color="#007700">))) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (</font><font color="#0000BB">$file </font><font color="#007700">!= </font><font color="#DD0000">"." </font><font color="#007700">&amp;&amp; </font><font color="#0000BB">$file </font><font color="#007700">!= </font><font color="#DD0000">".."</font><font color="#007700">) {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#DD0000">"$file</font><font color="#007700">\n</font><font color="#DD0000">"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">closedir</font><font color="#007700">(</font><font color="#0000BB">$handle</font><font color="#007700">);<br />}<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
    </P
><P
>&#13;     Veja também <A
HREF="function.is-dir.html"
><B
CLASS="function"
>is_dir()</B
></A
> e
     <A
HREF="function.glob.html"
><B
CLASS="function"
>glob()</B
></A
>.
    </P
></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.opendir.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Principal</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.rewinddir.html"
ACCESSKEY="N"
>Próxima</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>opendir</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.dir.html"
ACCESSKEY="U"
>Acima</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>rewinddir</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>