tags:

views:

733

answers:

2

The rmdir() function fails if the folder contains any files. I can loop through all of the the files in the directory with something like this:

foreach (scandir($dir) as $item) {
    if ($item == '.' || $item == '..') continue;
    unlink($dir.DIRECTORY_SEPARATOR.$item);
}
rmdir($dir);

Is there any way to just delete it all at once?

+2  A: 

Well, there's always

system("/bin/rm -rf " . escapeshellarg($dir));

where available.

chaos
Just saved me a whole bunch of useless processing of files I do not need. Thanks!
Scott Radcliff
A: 

As per this source;

Save some time, if you want to clean a directory or delete it and you're on windows.

Use This:

    chdir ($file_system_path);
    exec ("del *.* /s /q");

You can use other DEL syntax, or any other shell util. You may have to allow the service to interact with the desktop, as that's my current setting and I'm not changing it to test this.

Else you could find an alternative method here.

Kevin Boyd