file_unmanaged_delete_recursive

  1. drupal
    1. 8
    2. 7
Versions
8 – 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.

Parameters

$path A string containing either 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.

See also

file_unmanaged_delete()

Related topics

▾ 16 functions call file_unmanaged_delete_recursive()

DrupalWebTestCase::tearDown in modules/simpletest/drupal_web_test_case.php
Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix.
FileUnmanagedDeleteRecursiveTest::testDirectory in modules/simpletest/tests/file.test
Try deleting a directory with some files.
FileUnmanagedDeleteRecursiveTest::testEmptyDirectory in modules/simpletest/tests/file.test
Try deleting an empty directory.
FileUnmanagedDeleteRecursiveTest::testSingleFile in modules/simpletest/tests/file.test
Delete a normal file.
FileUnmanagedDeleteRecursiveTest::testSubDirectory in modules/simpletest/tests/file.test
Try deleting subdirectories with some files.
file_example_delete_directory_submit in examples/file_example/file_example.module
Submit handler for directory deletion.
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().
RetrieveFileTestCase::testFileRetrieving in modules/system/system.test
Invokes system_retrieve_file() in several scenarios.
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.
simpletest_uninstall in modules/simpletest/simpletest.install
Implements hook_uninstall().
update_delete_file_if_stale in modules/update/update.module
Delete stale files and directories from the Update manager disk cache.
update_manager_archive_extract in modules/update/update.manager.inc
Unpack a downloaded archive file.
UpgradePathTestCase::tearDown in modules/simpletest/tests/upgrade/upgrade.test
Override of DrupalWebTestCase::tearDown() specialized for upgrade testing.

Code

includes/file.inc, line 1321

<?php
function file_unmanaged_delete_recursive($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 drupal_rmdir($path);
  }
  return file_unmanaged_delete($path);
}
?>