You are here

function file_unmanaged_delete_recursive in Drupal 8

Same name and namespace in other branches
  1. 7 includes/file.inc \file_unmanaged_delete_recursive()

Deletes all files and directories in the specified filepath recursively.

If the specified path is a directory then the function will call itself recursively to process the contents. Once the contents have been removed the directory will also be removed.

If the specified path is a file then it will be passed to file_unmanaged_delete().

Note that this only deletes visible files with write permission.

Parameters

$path: A string containing either an URI or a file or directory path.

callable $callback: (optional) Callback function to run on each file prior to deleting it and on each directory prior to traversing it. For example, can be used to modify permissions.

Return value

TRUE for success or if path does not exist, FALSE in the event of an error.

Deprecated

in drupal:8.7.0 and is removed from drupal:9.0.0. Use \Drupal\Core\File\FileSystemInterface::deleteRecursive().

See also

file_unmanaged_delete()

https://www.drupal.org/node/3006851

Related topics

1 call to file_unmanaged_delete_recursive()
FileSystemDeprecationTest::testDeprecatedUnmanagedFileDeleteRecursive in core/tests/Drupal/KernelTests/Core/File/FileSystemDeprecationTest.php
@expectedDeprecation file_unmanaged_delete_recursive() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\File\FileSystemInterface::deleteRecursive(). See https://www.drupal.org/node/3006851.

File

core/includes/file.inc, line 867
API for handling file uploads and server file management.

Code

function file_unmanaged_delete_recursive($path, $callback = NULL) {
  @trigger_error('file_unmanaged_delete_recursive() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \\Drupal\\Core\\File\\FileSystemInterface::deleteRecursive(). See https://www.drupal.org/node/3006851.', E_USER_DEPRECATED);
  $callback = is_callable($callback) ? $callback : NULL;
  try {
    return \Drupal::service('file_system')
      ->deleteRecursive($path, $callback);
  } catch (FileException $e) {
    return FALSE;
  }
}