If the Opendir (Path,context) succeeds, the function returns a directory stream, otherwise it returns false and an error. You can hide the output of an error by adding "@" in front of the function name.
The Readdir () function returns an entry in a table of contents handle opened by Opendir (). If successful, the function returns a filename, otherwise it returns false.
The Scandir () function returns an array that contains the files and directories in the specified path.
If successful, returns an array that, if it fails, returns FALSE. If directory is not a directory, returns a Boolean value false
To pay the 2-paragraph read directory code, the pro-test effective
Displays the file name in the directory
Open the directory and read its content
if (Is_dir ($dir)) {
if ($dh = Opendir ($dir)) {while
($file = Readdir ($DH))!== false) {
echo "FileName:". $file. "<br>";
}
Closedir ($DH);
}
//Copy a directory file to another directory
copy_dir ($from _dir, $to _dir);
function Copy_dir ($from _dir, $to _dir) {if (!is_dir ($from _dir)) {return false;
echo "\ r \ n from:", $from _dir, '---to ', $to _dir;
$from _files = Scandir ($from _dir);
If the destination directory does not exist, attempt to create an if (!file_exists ($to _dir)) {@mkdir ($to _dir); } if (!empty ($from _files)) {foreach ($from _files as $file) {if ($file = = '. ' | | $file = = ' ... ')
{continue; if (Is_dir ($from _dir. $file)) {//If it is a directory, call itself Copy_dir ($from _dir. '/'. $file, $to _dir. '/'. $fil
e);
}else{//direct copy to target folder copy ($from _dir. '/'. $file, $to _dir. '/'. $file); }
}
}
}