You are here

function _xmlsitemap_delete_recursive in XML sitemap 7.2

Same name and namespace in other branches
  1. 8 xmlsitemap.module \_xmlsitemap_delete_recursive()
  2. 6.2 xmlsitemap.module \_xmlsitemap_delete_recursive()
  3. 2.x xmlsitemap.module \_xmlsitemap_delete_recursive()

Recursively delete all files and folders in the specified filepath.

This is a backport of Drupal 7's file_unmanaged_delete_recursive().

Note that this only deletes visible files with write permission.

Parameters

string $path: A filepath relative to the Drupal root directory.

bool $delete_root: A boolean if TRUE will delete the $path directory afterwards.

1 call to _xmlsitemap_delete_recursive()
xmlsitemap_clear_directory in ./xmlsitemap.module
Clear Directory.

File

./xmlsitemap.module, line 982
xmlsitemap XML sitemap

Code

function _xmlsitemap_delete_recursive($path, $delete_root = FALSE) {

  // Resolve streamwrapper URI to local path.
  $path = drupal_realpath($path);
  if (is_dir($path)) {
    $dir = dir($path);
    while (($entry = $dir
      ->read()) !== FALSE) {
      if ($entry == '.' || $entry == '..') {
        continue;
      }
      $entry_path = $path . '/' . $entry;
      file_unmanaged_delete_recursive($entry_path, TRUE);
    }
    $dir
      ->close();
    return $delete_root ? drupal_rmdir($path) : TRUE;
  }
  return file_unmanaged_delete($path);
}