note 116585 added to function.rmdir
| From: | wolfoneilatgmx.de | Date: | Mon, 26 Jan 2015 08:31:44 +0000 |
| Subject: | note 116585 added to function.rmdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201522@lists.php.net to get a copy of this message | ||
I was working on some Dataoperation, and just wanted to share an OOP method with you.
It just removes any contents of a Directory but not the target Directory itself! Its really nice if
you want to clean a BackupDirectory or Log.
Also you can test on it if something went wrong or if it just done its Work!
I have it in a FileHandler class for example, enjoy!
<?php
public function deleteContent($path){
try{
$iterator = new DirectoryIterator($path);
foreach ( $iterator as $fileinfo ) {
if($fileinfo->isDot())continue;
if($fileinfo->isDir()){
if(deleteContent($fileinfo->getPathname()))
@rmdir($fileinfo->getPathname());
}
if($fileinfo->isFile()){
@unlink($fileinfo->getPathname());
}
}
} catch ( Exception $e ){
// write log
return false;
}
return true;
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 82.198.197.2
----
Manual Page -- http://php.net/manual/en/function.rmdir.php
Edit -- https://master.php.net/note/edit/116585
Del: integrated -- https://master.php.net/note/delete/116585/integrated
Del: useless -- https://master.php.net/note/delete/116585/useless
Del: bad code -- https://master.php.net/note/delete/116585/bad+code
Del: spam -- https://master.php.net/note/delete/116585/spam
Del: non-english -- https://master.php.net/note/delete/116585/non-english
Del: in docs -- https://master.php.net/note/delete/116585/in+docs
Del: other reasons-- https://master.php.net/note/delete/116585
Reject -- https://master.php.net/note/reject/116585
Search -- https://master.php.net/manage/user-notes.php