mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-20 19:08:54 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@64852 c90b9560-bf6c-de11-be94-00142212c4b1
307 lines
8.3 KiB
XML
307 lines
8.3 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.28 $ -->
|
|
<reference id="ref.dir">
|
|
<title>Directory functions</title>
|
|
<titleabbrev>Directories</titleabbrev>
|
|
|
|
<partintro>
|
|
|
|
<simpara>
|
|
For related functions such as <function>dirname</function>,
|
|
<function>is_dir</function>, <function>mkdir</function>, and
|
|
<function>rmdir</function>, see the
|
|
<link linkend="ref.filesystem">Filesystem</link> section.
|
|
</simpara>
|
|
|
|
</partintro>
|
|
|
|
<refentry id="function.chroot">
|
|
<refnamediv>
|
|
<refname>chroot</refname>
|
|
<refpurpose>change the root directory</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool <function>chroot</function></funcdef>
|
|
<paramdef>string <parameter>directory</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<para>
|
|
Changes the root directory of the current process to
|
|
<parameter>directory</parameter>. Returns &false; if unable to
|
|
change the root directory, &true; otherwise.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
It's not wise to use this function when running in a webserver
|
|
environment, because it's not possible to reset the root
|
|
directory to / again at the end of the request. This function
|
|
will only function correct when running as CGI this way.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.chdir">
|
|
<refnamediv>
|
|
<refname>chdir</refname>
|
|
<refpurpose>change directory</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>bool <function>chdir</function></funcdef>
|
|
<paramdef>string <parameter>directory</parameter></paramdef>
|
|
</funcprototype>
|
|
</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>
|
|
<funcprototype>
|
|
<funcdef>object <function>dir</function></funcdef>
|
|
<paramdef>string <parameter>directory</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<para>
|
|
A pseudo-object oriented mechanism for reading a directory. The
|
|
given <parameter>directory</parameter> is opened. Two properties
|
|
are available once the 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">
|
|
<![CDATA[
|
|
$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();
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<note>
|
|
<para>
|
|
The order in which directory entries are returned by the read method is
|
|
system-dependent.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.closedir">
|
|
<refnamediv>
|
|
<refname>closedir</refname>
|
|
<refpurpose>close directory handle</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>void <function>closedir</function></funcdef>
|
|
<paramdef>resource <parameter>dir_handle</parameter></paramdef>
|
|
</funcprototype>
|
|
</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.getcwd">
|
|
<refnamediv>
|
|
<refname>getcwd</refname>
|
|
<refpurpose>gets the current working directory</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>string <function>getcwd</function></funcdef>
|
|
<void/>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<para>
|
|
Returns the current working directory.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.opendir">
|
|
<refnamediv>
|
|
<refname>opendir</refname>
|
|
<refpurpose>open directory handle</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>resource <function>opendir</function></funcdef>
|
|
<paramdef>string <parameter>path</parameter></paramdef>
|
|
</funcprototype>
|
|
</funcsynopsis>
|
|
<para>
|
|
Returns a directory handle to be used in subsequent
|
|
<function>closedir</function>, <function>readdir</function>, and
|
|
<function>rewinddir</function> calls.
|
|
</para>
|
|
<para>
|
|
If <parameter>path</parameter> is not a valid directory or the
|
|
directory can not be opened due to permission restrictions or
|
|
filesystem errors, <function>opendir</function> returns &false; and
|
|
generates a PHP error. You can suppress the error output of
|
|
<function>opendir</function> by prepending `@' to the front of
|
|
the function name.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title><function>opendir</function> example</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
if ($dir = @opendir("/tmp")) {
|
|
while (($file = readdir($dir)) !== false) {
|
|
echo "$file\n";
|
|
}
|
|
closedir($dir);
|
|
}
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.readdir">
|
|
<refnamediv>
|
|
<refname>readdir</refname>
|
|
<refpurpose>read entry from directory handle</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>string <function>readdir</function></funcdef>
|
|
<paramdef>resource <parameter>dir_handle</parameter></paramdef>
|
|
</funcprototype>
|
|
</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">
|
|
<![CDATA[
|
|
// Note that !== did not exist until 4.0.0-RC2
|
|
<?php
|
|
$handle=opendir('.');
|
|
echo "Directory handle: $handle\n";
|
|
echo "Files:\n";
|
|
while (false !== ($file = readdir($handle))) {
|
|
echo "$file\n";
|
|
}
|
|
closedir($handle);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
Note that <function>readdir</function> will return the <literal>.</literal>
|
|
and
|
|
<literal>..</literal> entries. If you don't want these, simply strip
|
|
them out:
|
|
<example>
|
|
<title>
|
|
List all files in the current directory and strip out <literal>.</literal>
|
|
and <literal>..</literal>
|
|
</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$handle = opendir('.');
|
|
while (false !== ($file = readdir($handle))) {
|
|
if ($file != "." && $file != "..") {
|
|
echo "$file\n";
|
|
}
|
|
}
|
|
closedir($handle);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<refentry id="function.rewinddir">
|
|
<refnamediv>
|
|
<refname>rewinddir</refname>
|
|
<refpurpose>rewind directory handle</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<funcsynopsis>
|
|
<funcprototype>
|
|
<funcdef>void <function>rewinddir</function></funcdef>
|
|
<paramdef>resource <parameter>dir_handle</parameter></paramdef>
|
|
</funcprototype>
|
|
</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
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../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
|
|
-->
|