You are here

function hackedProjectWebDownloader::remove_dir in Hacked! 7.2

Same name and namespace in other branches
  1. 6.2 includes/hacked_project.inc \hackedProjectWebDownloader::remove_dir()

Recursively delete all files and folders in the specified filepath, then delete the containing folder.

Note that this only deletes visible files with write permission.

Parameters

string $path: A filepath relative to file_directory_path.

File

includes/hackedProjectWebDownloader.inc, line 90

Class

hackedProjectWebDownloader
Base class for downloading remote versions of projects.

Code

function remove_dir($path) {
  if (is_file($path) || is_link($path)) {
    unlink($path);
  }
  elseif (is_dir($path)) {
    $d = dir($path);
    while (($entry = $d
      ->read()) !== FALSE) {
      if ($entry == '.' || $entry == '..') {
        continue;
      }
      $entry_path = $path . '/' . $entry;
      $this
        ->remove_dir($entry_path);
    }
    $d
      ->close();
    rmdir($path);
  }
  else {
    watchdog('hacked', 'Unknown file type(%path) stat: %stat ', array(
      '%path' => $path,
      '%stat' => print_r(stat($path), 1),
    ), WATCHDOG_ERROR);
  }
}