note 70525 deleted from function.rmdir by aidan
| From: | aidan@php.net | Date: | Wed, 15 Apr 2009 04:25:39 +0000 |
| Subject: | note 70525 deleted from function.rmdir by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153262@lists.php.net to get a copy of this message | ||
Note Submitter: FormatThis
----
@ null at php5 dot pl & stijnleenknegt< at >gmail< dot >com & mediengestalter at
gleichjetzt dot de:
[EDITORS NOTE: Mentioned Notes have all been Removed (Previous Examples)]
I believe the following is what you were trying to make happen. notes and echo commands have been
added so you can see what is being done as it happens and also threw in the actual rmdir function so
that the directories as well will be removed and not just the files.
<?php
function removeDir($path) {
// Add trailing slash to $path if one is not there
if (substr($path, -1, 1) != "/") {
$path .= "/";
}
foreach (glob($path . "*") as $file) {
if (is_file($file) === TRUE) {
// Remove each file in this Directory
unlink($file);
echo "Removed File: " . $file . "<br>";
}
else if (is_dir($file) === TRUE) {
// If this Directory contains a Subdirectory, run this Function on it
removeDir($file);
}
}
// Remove Directory once Files have been removed (If Exists)
if (is_dir($path) === TRUE) {
rmdir($path);
echo "<br>Removed Directory: " . $path . "<br><br>";
}
}
?>