note 70525 added to function.rmdir
| From: | FormatThis at osu1 dot php dot net | Date: | Thu, 19 Oct 2006 15:47:57 +0000 |
| Subject: | note 70525 added to function.rmdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-118776@lists.php.net to get a copy of this message | ||
@ null at php5 dot pl & stijnleenknegt< at >gmail< dot >com & mediengestalter at
gleichjetzt dot de:
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>";
}
}
?>
----
Server IP: 66.163.161.117
Probable Submitter: 67.155.78.83
----
Manual Page -- http://www.php.net/manual/en/function.rmdir.php
Edit -- https://master.php.net/note/edit/70525
Del: integrated -- https://master.php.net/note/delete/70525/integrated
Del: useless -- https://master.php.net/note/delete/70525/useless
Del: bad code -- https://master.php.net/note/delete/70525/bad+code
Del: spam -- https://master.php.net/note/delete/70525/spam
Del: non-english -- https://master.php.net/note/delete/70525/non-english
Del: in docs -- https://master.php.net/note/delete/70525/in+docs
Del: other reasons-- https://master.php.net/note/delete/70525
Reject -- https://master.php.net/note/reject/70525
Search -- https://master.php.net/manage/user-notes.php