You are here

function imce_mkdir_rmdir_recursive in IMCE Mkdir 6

Same name and namespace in other branches
  1. 7 imce_mkdir.inc \imce_mkdir_rmdir_recursive()

Recursive directory deletion

1 call to imce_mkdir_rmdir_recursive()
imce_mkdir_rmdir_batch in ./imce_mkdir.inc
Batch remove directories.

File

./imce_mkdir.inc, line 146

Code

function imce_mkdir_rmdir_recursive($path) {
  static $dirlen;
  if (!isset($dirlen)) {
    $dirlen = strlen(file_directory_path()) + 1;
  }
  if (is_dir($path) && !is_link($path)) {
    if ($handle = @opendir($path)) {
      while (($file = readdir($handle)) !== FALSE) {
        if ($file == '.' || $file == '..') {
          continue;
        }
        $filepath = $path . '/' . $file;
        if (!imce_mkdir_rmdir_recursive($filepath)) {
          drupal_set_message(t('%path could not be removed.', array(
            '%path' => substr($filepath, $dirlen),
          )), 'error');
          break;
        }
      }
      closedir($handle);
    }
    return @rmdir($path);
  }
  return imce_mkdir_unlink($path);
}