Support Forums

Full Version: Delete directory and all content
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Credits and Source: http://www.roscripts.com/

Name: Delete directory and all content
Description: This function deletes a directory with all of it's content. Second parameter is boolean to instruct the function if it should remove the directory or only the content.
Snippet:

PHP Code:
function rmdir_r $dir$DeleteMe TRUE )
{
    if ( ! 
$dh = @opendir $dir ) ) return;
    while ( 
false !== ( $obj readdir $dh ) ) )
    {
        if ( 
$obj == '.' || $obj == '..') continue;
        if ( ! @
unlink $dir '/' $obj ) ) rmdir_r $dir '/' $objtrue );
    }
    
    
closedir $dh );
    if ( 
$DeleteMe )
    {
        @
rmdir $dir );
    }



Thankyou for reading. Be happy always Smile