Remove Directory

<?php

$mypath = "mambo";

function rmdirr($dirname)
{
    // Sanity check
    if (!file_exists($dirname)) {
        return false;
    }
 
    // Simple delete for a file
    if (is_file($dirname)) {
        return unlink($dirname);
    }
 
    // Loop through the folder
    $dir = dir($dirname);
    while (false !== $entry = $dir->read()) {
        // Skip pointers
        if ($entry == '.' || $entry == '..') {
            continue;
        }
 
        // Recurse
        rmdirr("$dirname/$entry");
    }
 
    // Clean up
    $dir->close();
    return rmdir($dirname);
}

rmdirr("$mypath");
 
?>

2 Responses so far »

  1. 1

    Anna said,

    Cool!.. Nice work…s

  2. 2

    sandrar said,

    Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.


Comment RSS · TrackBack URI

Say your words