note 89497 modified in function.rmdir by danbrown

From: Date: Wed, 11 Mar 2009 14:05:51 +0000
Subject: note 89497 modified in function.rmdir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-151732@lists.php.net to get a copy of this message
Thanks for that compact recursive delete function. Note that it does not delete the directory initially passed to it. rmdir it afterwards or modify the function like this: <?php function rmdir_recurse($path) { $path= rtrim($path, '/').'/'; $handle = opendir($path); for (;false !== ($file = readdir($handle));) if($file != "." and $file != ".." ) { $fullpath= $path.$file; if( is_dir($fullpath) ) { rmdir_recurse($fullpath); } else { unlink($fullpath); } } closedir($handle); rmdir($path); } ?> [NOTE BY danbrown AT php DOT net: This function was originally written by (elprez AT free DOT fr) on 02-DEC-2008 with the following note: "A simple recursive function freely inspired from hoffmeister."] --was-- Thanks for that compact recursive delete function. Note that it does not delete the directory initially passed to it. rmdir it afterwards or modify the function like this: function rmdir_recurse($path) { $path= rtrim($path, '/').'/'; $handle = opendir($path); for (;false !== ($file = readdir($handle));) if($file != "." and $file != ".." ) { $fullpath= $path.$file; if( is_dir($fullpath) ) { rmdir_recurse($fullpath); } else { unlink($fullpath); } } closedir($handle); rmdir($path); } http://php.net/manual/en/function.rmdir.php

« previous php.notes (#151732) next »