function 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.


$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


Related topics

13 calls to file_unmanaged_delete_recursive()
DrupalWebTestCase::tearDown in drupal/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 drupal/modules/simpletest/tests/file.test
Try deleting a directory with some files.
FileUnmanagedDeleteRecursiveTest::testEmptyDirectory in drupal/modules/simpletest/tests/file.test
Try deleting an empty directory.
FileUnmanagedDeleteRecursiveTest::testSingleFile in drupal/modules/simpletest/tests/file.test
Delete a normal file.
FileUnmanagedDeleteRecursiveTest::testSubDirectory in drupal/modules/simpletest/tests/file.test
Try deleting subdirectories with some files.

... See full list


drupal/includes/, line 1375
API for handling file uploads and server file management.


function file_unmanaged_delete_recursive($path) {
  if (is_dir($path)) {
    $dir = dir($path);
    while (($entry = $dir
      ->read()) !== FALSE) {
      if ($entry == '.' || $entry == '..') {
      $entry_path = $path . '/' . $entry;
    return drupal_rmdir($path);
  return file_unmanaged_delete($path);