note 86112 modified in function.rmdir by danbrown

From: Date: Sat, 04 Oct 2008 15:51:19 +0000
Subject: note 86112 modified in function.rmdir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-145052@lists.php.net to get a copy of this message
here is a little improved 'removing' function with DirectoryIterator: note for PHP on windows: if using the iterator and recursively removing dirs and files, u need to unset() before leaving/continue the foreach! ( permission denied problem...) <?php function removeRessource( $_target ) { //file? if( is_file($_target) ) { if( is_writable($_target) ) { if( @unlink($_target) ) { return true; } } return false; } //dir? if( is_dir($_target) ) { if( is_writeable($_target) ) { foreach( new DirectoryIterator($_target) as $_res ) { if( $_res->isDot() ) { unset($_res); continue; } if( $_res->isFile() ) { removeRessource( $_res->getPathName() ); } elseif( $_res->isDir() ) { removeRessource( $_res->getRealPath() ); } unset($_res); } if( @rmdir($_target) ) { return true; } } return false; } } ? --was-- here is a little improved 'removing' function with DirectoryIterator: note for PHP on windows: if using the iterator and recursively removing dirs and files, u need to unset() before leaving/continue the foreach! ( permission denied problem...) <?php function removeRessource( $_target ) { $_target = realpath($_target); //file? if( is_file($_target) ) { if( is_writable($_target) ) { if( @unlink($_target) ) { return true; } } return false; } //dir? if( is_dir($_target) ) { if( is_writeable($_target) ) { foreach( new DirectoryIterator($_target) as $_res ) { if( $_res->isDot() ) { unset($_res); continue; } if( $_res->isFile() ) { removeRessource( $_res->getPathName() ); } elseif( $_res->isDir() ) { removeRessource( $_res->getRealPath() ); } unset($_res); } if( @rmdir($_target) ) { return true; } } return false; } } ? http://php.net/manual/en/function.rmdir.php

« previous php.notes (#145052) next »