Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code enhancement 1

Status
Not open for further replies.

Sleidia

Technical User
May 4, 2001
1,284
FR
Hi guys,

In the function below, how should I edit the code in order to make sure that the function returns true only after $dir have been totally emptied?

Would (filesize($dir) == 0) be a viable option?
I'm not sure an empty directory really returns 0 bytes.

Thanks a lot!

Code:
function hd_dir_clear($dir) {

$handle = opendir($dir);

   while ($file = readdir($handle)) {
   
       if ($file != "." AND $file != "..") {
            
        $fullpath = $dir . "/" . $file;
           
            if (!is_dir($fullpath)) {
           
            unlink($fullpath);
            
            } else {
            
            hd_dir_clear($fullpath);
            
            }
            
        }
        
    }

closedir($handle);

    if(?????) {
    
    return true;
    
    } else {
    
    return false;
    
    }

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top