I wrote code for a program to delete folders. for details, refer.
The code is as follows:
Header ('content-type: text/html; charset = utf-8 ');
Function delFile ($ fpath ){
$ Filesize = array ();
$ Filepath = iconv ('gb2312', 'utf-8', $ fpath );
If (is_dir ($ fpath )){
If ($ dh = opendir ($ fpath )){
While ($ file = readdir ($ dh ))! = False ){
If ($ file! = '.' & $ File! = '..'){
$ Filesize [] = delFile ($ fpath. '/'. $ file );
}
}
Closedir ($ dh );
}
/*
* Convenient statistics on the number of directories
*/
$ Filesize ['file'] = 0;
If (@ rmdir ($ fpath) === true ){
Echo "{$ filepath}... deleted successfully.
\ N ";
} Else {
Echo "{$ filepath} ...... deletion failed.
\ N ";
}
} Else {
If (is_file ($ fpath )){
$ Filesize [] = $ fsize = filesize ($ fpath );
If (@ unlink ($ fpath) === true ){
Echo "{$ filepath}... {$ fsize} K ...... deleted successfully
\ N ";
} Else {
Echo "{$ filepath}... {$ fsize} K ...... deletion failed
\ N ";
}
}
}
Return $ filesize;
}
/*
* Function getArrSum (array & $ arr) array summation
* Array & $ arr processed array
*/
Function getArrSum (& $ arr ){
If (is_array ($ arr )){
Foreach ($ arr as & $ value ){
$ Value = getArrSum ($ value );
}
Return array_sum ($ arr );
} Else {
Return $ arr;
}
}
$ Fpath = 'd:/test ';
$ Filesize = delFile ($ fpath );
$ Size = getArrSum ($ filesize );
Printf ('save for you: %. 3fM space', $ size/(1024*1024 ));
?>
You just need to create a test folder under drive D, and then just pull something into it to test it.