note 78617 added to function.rmdir

From: Date: Fri, 19 Oct 2007 14:08:47 +0000
Subject: note 78617 added to function.rmdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-131543@lists.php.net to get a copy of this message
The PHP4 version below can not delete subfolders, just files. Here is a complete PHP4/5 recursive folder/subfolder delete function: <?php function deltree($path) { if (is_dir($path)) { if (version_compare(PHP_VERSION, '5.0.0') < 0) { $entries = array(); if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) $entries[] = $file; closedir($handle); } } else { $entries = scandir($path); if ($entries === false) $entries = array(); // just in case scandir fail... } foreach ($entries as $entry) { if ($entry != '.' && $entry != '..') { deltree($path.'/'.$entry); } } return rmdir($path); } else { return unlink($path); } } ?> Thanks to the two codes below for the jump start on this one. ---- Server IP: 195.149.248.161 Probable Submitter: 77.85.149.173 ---- Manual Page -- http://www.php.net/manual/en/function.rmdir.php Edit -- https://master.php.net/note/edit/78617 Del: integrated -- https://master.php.net/note/delete/78617/integrated Del: useless -- https://master.php.net/note/delete/78617/useless Del: bad code -- https://master.php.net/note/delete/78617/bad+code Del: spam -- https://master.php.net/note/delete/78617/spam Del: non-english -- https://master.php.net/note/delete/78617/non-english Del: in docs -- https://master.php.net/note/delete/78617/in+docs Del: other reasons-- https://master.php.net/note/delete/78617 Reject -- https://master.php.net/note/reject/78617 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131543) next »