file_unmanaged_delete_recursive

Versions
7
file_unmanaged_delete_recursive($path)

Recursively delete all files and directories in the specified filepath.

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.

See also

file_unmanaged_delete()

Parameters

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

Return value

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

Related topics

▾ 5 functions call file_unmanaged_delete_recursive()

file_unmanaged_delete_recursive in includes/file.inc
Recursively delete all files and directories in the specified filepath.
image_style_flush in modules/image/image.module
Flush cached media for a style.
image_uninstall in modules/image/image.install
Implements hook_uninstall().
simpletest_clean_temporary_directories in modules/simpletest/simpletest.module
Find all leftover temporary directories and remove them.
simpletest_run_tests in modules/simpletest/simpletest.module
Actually runs tests.

Code

includes/file.inc, line 1007

<?php
function file_unmanaged_delete_recursive($path) {
  // 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);
    }
    $dir->close();
    return rmdir($path);
  }
  return file_unmanaged_delete($path);
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.