Predefined constants:
DIRECTORY_SEPARATOR (string): Directory separator
PATH_SEPARATOR (string): path separator
bool chdir ( string $directory ) — change directory
Copy code The code is as follows:
echo getcwd() . "n";
chdir('public_html');
echo getcwd() . "n";
bool chroot ( string $directory ) — Changing the root directory is only possible if the system supports it and is running the CLI, CGI or embedded SAPI version.
dir::dir (string $directory)—directory class, there are three methods available: read, rewind (redirect the position pointer inside the file to the beginning of a data stream) and close
Copy code The code is as follows:
$d = dir("E:/work/html");
foreach($d as $k=>$v){
echo $k.'->' .$v. '
';
}
while(false ! == ($entry = $d->read())){
echo $entry."
";
}
$d->close();
void closedir ( resource $dir_handle ) — Close the directory handle
Copy code The code is as follows:
$dir = "/etc/php5/";
if (is_dir($dir)) {
if ($dh = opendir($dir)){
$directory = readdir($dh);
closedir($dh);
}
}
string getcwd ( void )— Get the current working directory
resource opendir ( string $path [, resource $context ] ) — Open directory handle
string readdir ( resource $dir_handle ) — Read an entry from a directory handle
Copy code The code is as follows:
if ($handle = opendir('/path/to/files')) {
echo "Directory handle: $handlen";
echo "Files:n";
while (false !== ($file = readdir($handle))) {
echo "$filen ";
}
closedir($handle);
}
void rewinddir ( resource $dir_handle ) — Resets the directory stream specified by dir_handle to the beginning of the directory
array scandir ( string $directory [, int $sorting_order [, resource $context ]] ) — List files and directories in the specified path
Copy code The code is as follows:
$dir = '/tmp';
$files1 = scandir($dir );
$files2 = scandir($dir, 1);
print_r($files1);
print_r($files2);
http://www.bkjia.com/PHPjc/326745.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326745.htmlTechArticlePredefined constants: DIRECTORY_SEPARATOR (string): Directory separator PATH_SEPARATOR (string): Path separator bool chdir (string $directory )—The code to change the directory copy code is as follows...