note 78617 deleted from function.rmdir by aidan

From: Date: Wed, 15 Apr 2009 04:22:51 +0000
Subject: note 78617 deleted from function.rmdir by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153246@lists.php.net to get a copy of this message
Note Submitter: contacts [from] nexus-soft [dot] org ---- 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.

« previous php.notes (#153246) next »