Recently writing code requires the function of copying folders and all files in these folders. you can use this function to delete these files. you can use the custom functions of xcopy and deldir, it is much more convenient.
The code is as follows:
/* Copy the xCopy function usage:
* XCopy ("feiy", "feiy2", 1): copy the files in feiy to feiy2, including subdirectories.
* XCopy ("feiy", "feiy2", 0): copy the file under feiy to feiy2, excluding subdirectories.
* Parameter description:
* $ Source: source directory name
* $ Destination: target directory name
* $ Child: indicates whether to include sub-directories during replication.
*/
Function xCopy ($ source, $ destination, $ child ){
If (! File_exists ($ destination ))
{
If (! Mkdir (rtrim ($ destination, '/'), 0777 ))
{
// $ Err-> add ($ _ LANG ['cannt _ mk_dir ']);
Return false;
}
@ Chmod ($ destination, 0777 );
}
If (! Is_dir ($ source )){
Return 0;
}
If (! Is_dir ($ destination )){
Mkdir ($ destination, 0777 );
}
$ Handle = dir ($ source );
While ($ entry = $ handle-> read ()){
If ($ entry! = ".") & ($ Entry! = "..")){
If (is_dir ($ source. "/". $ entry )){
If ($ child)
XCopy ($ source. "/". $ entry, $ destination. "/". $ entry, $ child );
}
Else {
Copy ($ source. "/". $ entry, $ destination. "/". $ entry );
}
}
}
Return 1;
}
/* Delete deldir function usage:
* Deldidr ("feiy"): deletes feiy, including subdirectories.
* Parameter description:
* $ Dir: name of the directory to be deleted
*/
Function deldir ($ dir ){
If (! File_exists ($ dir) {return true;
} Else {@ chmod ($ dir, 0777 );}
$ Dh = opendir ($ dir );
While ($ file = readdir ($ dh )){
If ($ file! = "." & $ File! = ".."){
$ Fullpath = $ dir. "/". $ file;
If (! Is_dir ($ fullpath )){
Unlink ($ fullpath );
} Else {
Deldir ($ fullpath );
}
}
}
Closedir ($ dh );
If (rmdir ($ dir )){
Return true;
} Else {
Return false;
}
}
?>