note 81844 deleted from function.rmdir by aidan

From: Date: Wed, 15 Apr 2009 04:21:45 +0000
Subject: note 81844 deleted from function.rmdir by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153235@lists.php.net to get a copy of this message
Note Submitter: LiTuS ---- This is another deltree function version from boccheciampe (and lukas and first one from vboedefeld) Notice that I put the rmdir sentence out of the foreach loop. In the boccheciampe version the rmdir was in the foreach loop and I think that it's an error because it tries to delete the same directory on every loop. And this version propagates the result of the operation for a better control of it. function esborrar_directori($ruta) { if (!empty($ruta) && $ruta != '.' && $ruta != '..' ) { if (is_dir($ruta)) { foreach(glob($ruta.'/*') as $node) { if (is_dir($node) && !is_link($node)) $swOK = ($node == '.' || $node == '..' || esborrar_directori($node)); else $swOK = unlink($node); if (!$swOK) return false; } return rmdir($ruta); } } return false; }

« previous php.notes (#153235) next »