note 50161 deleted from function.rmdir by aidan

From: Date: Wed, 15 Apr 2009 04:29:34 +0000
Subject: note 50161 deleted from function.rmdir by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153280@lists.php.net to get a copy of this message
Note Submitter: Daniellehr[-at-]gmx[-dot-]de ---- If you want to delete a folder with its all content and sub-content you can use this recursive-working function (WARNING: after using the function the folder is completely deleted!): <?php function delDir($dirName) { if(empty($dirName)) { return; } if(file_exists($dirName)) { $dir = dir($dirName); while($file = $dir->read()) { if($file != '.' && $file != '..') { if(is_dir($dirName.'/'.$file)) { delDir($dirName.'/'.$file); } else { @unlink($dirName.'/'.$file) or die('File '.$dirName.'/'.$file.' couldn\'t be deleted!'); } } } @rmdir($dirName.'/'.$file) or die('Folder '.$dirName.'/'.$file.' couldn\'t be deleted!'); } else { echo 'Folder "<b>'.$dirName.'</b>" doesn\'t exist.'; } } ?>

« previous php.notes (#153280) next »