function unish_file_delete_recursive

8.0.x unish_file_delete_recursive($dir, $force = FALSE, $follow_symlinks = FALSE)
6.x unish_file_delete_recursive($dir, $force = FALSE, $follow_symlinks = FALSE)
7.x unish_file_delete_recursive($dir, $force = FALSE, $follow_symlinks = FALSE)
4.x unish_file_delete_recursive($dir)
5.x unish_file_delete_recursive($dir)
master unish_file_delete_recursive($dir, $force = TRUE, $follow_symlinks = FALSE)

Deletes the specified file or directory and everything inside it.

Usually respects read-only files and folders. To do a forced delete use drush_delete_tmp_dir() or set the parameter $forced.

To avoid permission denied error on Windows, make sure your CWD is not inside the directory being deleted.

This is essentially a copy of drush_delete_dir().

@todo This sort of duplication isn't very DRY. This is bound to get out of sync with drush_delete_dir(), as in fact it already has before.


string $dir: The file or directory to delete.

bool $force: Whether or not to try everything possible to delete the directory, even if it's read-only. Defaults to FALSE.

bool $follow_symlinks: Whether or not to delete symlinked files. Defaults to FALSE--simply unlinking symbolic links.

Return value

bool FALSE on failure, TRUE if everything was deleted.

See also


7 calls to unish_file_delete_recursive()
archiveDumpCase::testArchiveRestoreNoCore in tests/archiveDumpTest.php
Test archive-restore for a site archive (--no-core).
archiveDumpCase::unTar in tests/archiveDumpTest.php
Untar an archive and return the path to the untarred folder.
drushScriptCase::remove_site_local_drush in tests/drushScriptTest.php
pmDownloadCase::testDestination in tests/pmDownloadTest.php
UnishTestCase::setUpFreshSandBox in tests/Unish/UnishTestCase.php
Remove any pre-existing sandbox, then create a new one.

... See full list


tests/, line 115
Initialize a sandboxed environment. Starts with call unish_init() at bottom.


function unish_file_delete_recursive($dir, $force = TRUE, $follow_symlinks = FALSE) {
  // Do not delete symlinked files, only unlink symbolic links
  if (is_link($dir) && !$follow_symlinks) {
    return unlink($dir);
  // Allow to delete symlinks even if the target doesn't exist.
  if (!is_link($dir) && !file_exists($dir)) {
    return TRUE;
  if (!is_dir($dir)) {
    if ($force) {
      // Force deletion of items with readonly flag.
      @chmod($dir, 0777);
    return unlink($dir);
  if (unish_delete_dir_contents($dir, $force) === FALSE) {
    return FALSE;
  if ($force) {
    // Force deletion of items with readonly flag.
    @chmod($dir, 0777);
  return rmdir($dir);