PHP recursively copy files and directories, how to resolve
Source: Internet
Author: User
PHP recursively copy files and directories
Function del ($path) {
$handle = Opendir ($path);
Readdir ($handle);
Readdir ($handle), while (false!== ($file = Readdir ($handle))) {
$file = $path. " /". $file;
if (Is_dir ($file)) {
Del ($file);
}else{
if (unlink ($file)) {
echo "File". $file. " Success "." \ r \ n ";
}else{
echo "File". $file. " Failed "." \ r \ n ";
}
}
}
Closedir ($handle);
if (RmDir ($path)) {
echo "Catalog". $path. " Delete succeeded "." \ r \ n ";
}else{
echo "Catalog". $path. " Delete Failed "." \ r \ n ";
}
}
Del (' d:/123 ');
?>
Why use two times Readdir ($handle);? Solve, detail point, use one time why wrong?
------Solution--------------------
There are two special directories under a directory. And.. , representing this directory and the parent directory, these two readdir ($handle) is to read the two special directories to skip, so as to correctly manipulate the files and subdirectories under the specified directory.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.