note 70909 added to function.rmdir
| From: | sarangan dot thuraisingham at gmail dot com | Date: | Fri, 03 Nov 2006 20:52:41 +0000 |
| Subject: | note 70909 added to function.rmdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119349@lists.php.net to get a copy of this message | ||
I installed Joomla CMS and the files where under apache user. So I couldn't delete from my SSH
login. Your little function helped. But, you forgot about hidden files in Unix. Filenames beginning
with a . are not returned in the glob list. So the modified code looks like this:
<?php
function removeDir($path) {
// Add trailing slash to $path if one is not there
if (substr($path, -1, 1) != "/") {
$path .= "/";
}
$normal_files = glob($path . "*");
$hidden_files = glob($path . "\.?*");
$all_files = array_merge($normal_files, $hidden_files);
foreach ($all_files as $file) {
# Skip pseudo links to current and parent dirs (./ and ../).
if (preg_match("/(\.|\.\.)$/", $file))
{
continue;
}
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>";
}
}
#To remove a dir:
removeDir('/home/fhlinux206/t/thuraisingham.net/tmp/');
?>
----
Server IP: 216.194.113.175
Probable Submitter: 80.229.6.18
----
Manual Page -- http://www.php.net/manual/en/function.rmdir.php
Edit -- https://master.php.net/note/edit/70909
Del: integrated -- https://master.php.net/note/delete/70909/integrated
Del: useless -- https://master.php.net/note/delete/70909/useless
Del: bad code -- https://master.php.net/note/delete/70909/bad+code
Del: spam -- https://master.php.net/note/delete/70909/spam
Del: non-english -- https://master.php.net/note/delete/70909/non-english
Del: in docs -- https://master.php.net/note/delete/70909/in+docs
Del: other reasons-- https://master.php.net/note/delete/70909
Reject -- https://master.php.net/note/reject/70909
Search -- https://master.php.net/manage/user-notes.php