Home > Backend Development > PHP Tutorial > Directory management functions of PHP_PHP tutorial

Directory management functions of PHP_PHP tutorial

WBOY
Release: 2016-07-13 10:59:01
Original
823 people have browsed it

chdir: Change directory.
dir: directory category class.
closedir: close the directory handle.
opendir: open directory handle.
readdir: read directory handle.
rewinddir: Reset directory handle.

chdir
Change directory.
Syntax: int chdir(string directory);
Return value: integer
Function type: File access
Content Description This function is used to change the current PHP execution directory to the new directory. Returns false if it cannot be changed, true if successful.

dir
Directory category class.
Syntax: new dir(string directory);
Return value: class
Function type: File access
Content Description This is a similar object-oriented category class, used to read directories. When the directory parameter directory is opened, two attributes are available: the handle attribute is like readdir(), rewinddir() and closedir() used by other non-class functions; the path attribute configures the path parameter after opening the directory. This class has three methods: read, rewind and close.

Usage example
$d = dir("/etc");
echo "Handle: ".$d->handle."
n";
echo "Path: ".$d->path."
n";
while($entry=$d->read()) {
echo $entry."
n";
}
$d->close();
?>

closedir
Close directory handle.
Syntax: void closedir(int dir_handle);
Return value: None
Function type: File access
Content Description
This function is used to close the dir_handle of the directory data stream. The directory operated by this dir_handle parameter must be opened by opendir() before it can be used.

opendir
Open directory handle.
Syntax: int opendir(string path);
Return value: integer
Function type: File access
Content Description
This function is used to open the directory data stream. The returned integer is a handle that can be manipulated by other directory functions.

readdir
Read directory handle.
Syntax: string readdir(int dir_handle);
Return value: string
Function type: File access
Content Description This function is used to read the directory. Returns the names of files in a directory, read without any special order.
Usage Example This example lists all files in the current directory
$handle=opendir('.');
echo "Directory handle: $handle ";
echo "File: ";
while ($file = readdir($handle)) {
echo "$file ";
}
closedir($handle);
?>

rewinddir
Reset directory handle.
Syntax: void rewinddir(int dir_handle);
Return value: None
Function type: File access
Content Description This function is used to reset the directory data flow to the beginning.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631973.htmlTechArticlechdir: Change directory. dir: directory category class. closedir: close the directory handle. opendir: open directory handle. readdir: read directory handle. rewinddir: Reset directory handle. ...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template