note 50438 added to function.rmdir

From: Date: Mon, 28 Feb 2005 17:03:54 +0000
Subject: note 50438 added to function.rmdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-85677@lists.php.net to get a copy of this message
Warning! On Unix-type systems, most of the "delete directory tree" functions posted here will follow & delete symbolic links (which is not what you'd expect of, say, rm-rf) so you might find more than you bargained for getting wiped. Here's a quick kludge of an earlier submission (by tekangel) that avoids this by default. Make sure it does what you want before you uncomment the unlink and rmdir commands! <? function rmdirRecursive($path,$followLinks=false) { $dir = opendir($path) ; while ( $entry = readdir($dir) ) { if ( is_file( "$path/$entry" ) || ((!$followLinks) && is_link("$path/$entry")) ) { echo ( "unlink $path/$entry;\n" ); // Uncomment when happy! //unlink( "$path/$entry" ); } elseif ( is_dir( "$path/$entry" ) && $entry!='.' && $entry!='..' ) { rmdirRecursive( "$path/$entry" ) ; } } closedir($dir) ; echo "rmdir $path;\n"; // Uncomment when happy! // return rmdir($path); } ?> ---- Manual Page -- http://www.php.net/manual/en/function.rmdir.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50438 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50438&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50438&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50438&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50438&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50438&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50438&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#85677) next »