It mainly includes some functions chdir used for operations on files and folders
: changing directories.
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 directory where php is executed to a new directory. If it cannot be changed, it returns false, and if it succeeds, it returns true.
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 examples
<?
$d = dir("/etc");
echo "handle: ".$d->handle."<br>n";
echo "path: ".$d->path."<br>n";
while($entry=$d->read()) {
echo $entry."<br>n";
}
$d->close();
?>
closedir
Close the 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 the 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 operated on 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: List all files in the current directory
<?php
$handle=opendir('.');
echo "Directory handle: $handlen";
echo "File:n";
while ($file = readdir($handle)) {
echo "$filen";
}
closedir($handle);
?>
rewinddir
Reset the 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.