note 70525 modified in function.rmdir by bobby

From: Date: Thu, 19 Oct 2006 15:53:57 +0000
Subject: note 70525 modified in function.rmdir by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-118779@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: [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>"; } } ?> --was-- @ 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>"; } } ?> http://php.net/manual/en/function.rmdir.php

« previous php.notes (#118779) next »