webCOMAND

util::empty_directory()

Delete all files and folders from a directory, recursively.

Prototype

empty_directory(string $path, bool $force = FALSE)

Parameters

  • path - Path to the folder to empty.
  • force - TRUE to delete files and folders, even they are outside the webCOMAND Files folder.

Exceptions

The function will throw an exception if the path can not be emptied.

Example

// recursively delete all subfolders and files of a directory
try {
    \io_comand_file\util\empty_directory('dir');
} catch(\exception $e) {
    \comand::log_error("Could not delete dir: " . $e->getMessage());
}