Welcome Guest, Not a member yet? Register   Sign In
Deleting directory
#1

[eluser]alrightythen[/eluser]
Hi

I'm trying to delete a directory with all of its subdirectory and files. I've seen a lot of scripts online but none of them seem to work I must be doing something wrong I just don't know what it is.

I've set my write permission to 777 through coda.

here's my code..
Code:
function remove_dir($current_dir) {
    
        if($dir = @opendir($current_dir)) {
            while (($f = readdir($dir)) !== false) {
                if($f > '0' and filetype($current_dir.$f) == "file") {
                    unlink($current_dir.$f);
                } elseif($f > '0' and filetype($current_dir.$f) == "dir") {
                    remove_dir($current_dir.$f."\\");
                }
            }
            closedir($dir);
            rmdir($current_dir);
        }
    }

And here's the usage...
Code:
$dirname = base_url().'uploads/'.$id.'/';
$this->remove_dir($dirname);
#2

[eluser]Phil Sturgeon[/eluser]
You can't delete a URL, it has to be a path.

I just load the file_helper and run:

Code:
$dir = BASEPATH . 'somefolder';
delete_files($dir, TRUE);
unlink($dir);
#3

[eluser]alrightythen[/eluser]
[quote author="Phil Sturgeon" date="1266957945"]You can't delete a URL, it has to be a path.

I just load the file_helper and run:

Code:
$dir = BASEPATH . 'somefolder';
delete_files($dir, TRUE);
unlink($dir);
[/quote]

you're right, thank you so much!




Theme © iAndrew 2016 - Forum software by © MyBB