Jump to content

Directory and content deletion


mcmuney

Recommended Posts

I modified the 1st line and then attempted it and this time I got many more errors, am I missing something?

 

<?
if ($handle = opendir($paththumbs)) {
    while (false !== ($file = readdir($handle))) {
       unlink($file);
    }
    closedir($handle);
}
rmdir($paththumbs);
?>

try to echo your files under that dir

 

<?
if ($handle = opendir($paththumbs)) {
    while (false !== ($file = readdir($handle))) {
       if($file  == '.'|| $file  == '..'){echo  'this is not directoty<br/>';}
       else  { echo $file.'<br/>';}
    }
    closedir($handle);
}

?>

 

try and see what it returns

 

or maybe this

<?
if ($handle = opendir($paththumbs)) {
    while (false !== ($file = readdir($handle))) {
       unlink($paththumbs.'/'.$file);
    }
    closedir($handle);
}
rmdir($paththumbs);
?>

Can you elaborate on that a bit more? I'm not sure how to incorporate that into the existing code.

write below set of code replacing <directoryName>  where you are writing your present code.Comment that first and try this two lines of code.

 

$cmd= 'rm -rf <directoryName>' ;

 

This command will delete the directory even if it contains the content in it.

 

exec($cmd);

 

Regards

Got this from http://nz.php.net/unlink

 

function SureRemoveDir($dir, $DeleteMe) {
    if(!$dh = @opendir($dir)) return;
    while (false !== ($obj = readdir($dh))) {
        if($obj=='.' || $obj=='..') continue;
        if (!@unlink($dir.'/'.$obj)) SureRemoveDir($dir.'/'.$obj, true);
    }

    closedir($dh);
    if ($DeleteMe){
        @rmdir($dir);
    }
}

SureRemoveDir($paththumbs, true) ;

 

Scott.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.