Support Forums
Delete directory and all content - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21)
+---- Thread: Delete directory and all content (/showthread.php?tid=2689)



Delete directory and all content - zone - 11-08-2009

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