You are here

function _xmlsitemap_delete_recursive in XML sitemap 6.2

Same name and namespace in other branches
  1. 8 xmlsitemap.module \_xmlsitemap_delete_recursive()
  2. 7.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

$path: A filepath relative to file_directory_path.

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

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

File

./xmlsitemap.module, line 861
Main file for the xmlsitemap module.

Code

function _xmlsitemap_delete_recursive($path, $delete_root = FALSE) {
  if (is_dir($path)) {
    $dir = dir($path);
    while (($entry = $dir
      ->read()) !== FALSE) {
      if ($entry == '.' || $entry == '..') {
        continue;
      }
      $entry_path = $path . '/' . $entry;
      _xmlsitemap_delete_recursive($entry_path, TRUE);
    }
    $dir
      ->close();
    return $delete_root ? rmdir($path) : TRUE;
  }
  return file_delete($path);
}