Emptying a Directory of All Files and Folders


You want to empty a directory completely of it's contents.

But you want to retain the directory itself.


Use the File::cleanDirectory() method.

$success = File::cleanDirectory($directory);

The method will return false if the directory doesn't exist. Otherwise it returns true when complete.


This is a wrapper on File::deleteDirectory().

It operates just as File::deleteDirectory() does but it always retains the directory instead of deleting it.

See Recursively Deleting a Directory for more details.

comments powered by Disqus