views:

227

answers:

3

Hello,

How do I do that? Is there any method provided by kohana 3?

+2  A: 

To delete a directory and all this content, you'll have to write some recursive deletion function -- or use one that already exists.

You can find some examples in the user's notes on the documentation page of rmdir ; for instance, here's the one proposed by bcairns in august 2009 (quoting) :

<?php
// ensure $dir ends with a slash
function delTree($dir) {
    $files = glob( $dir . '*', GLOB_MARK );
    foreach( $files as $file ){
        if( substr( $file, -1 ) == '/' )
            delTree( $file );
        else
            unlink( $file );
    }
    rmdir( $dir );
}
?> 
Pascal MARTIN
$files = glob( $dir . '*', GLOB_MARK ); -> Please explain this line. Thanks.
ed
The `glob` function *(see http://php.net/glob )* will return all files that match the pattern -- and `*` will match all files, which means glob will return a list of all files in the directory pointed by `$dir` ;; `GLOB_MARK` means "*Adds a slash to each directory returned*"
Pascal MARTIN
A: 

have you tried unlink in the directory ?

      chdir("file");
   foreach (glob("N*") as $filename )
      {
        unlink($filename);
      }

This deletes filenames starting from N

mithunmo
A: 

I'm not sure about Kahone 3, but I'd use a DirectoryIterator() and unlink()in conjunction.

Moshe