You are here

function session_cache_file_rrmdir in Session Cache API 8

Same name and namespace in other branches
  1. 7 session_cache_file/session_cache_file.install \session_cache_file_rrmdir()

Recursively delete a directory and all files in it.

PHP's rmdir() only deletes if the directory is empty so we empty directories recursively before calling rmdir().

Parameters

string $dir:

1 call to session_cache_file_rrmdir()
session_cache_file_uninstall in session_cache_file/session_cache_file.install
Implements hook_uninstall().

File

session_cache_file/session_cache_file.install, line 28
session_cache_file.install

Code

function session_cache_file_rrmdir($dir) {
  if (is_dir($dir)) {
    $files = scandir($dir);
    foreach ($files as $file) {
      if ($file != '.' && $file != '..') {
        if (is_dir("{$dir}/{$file}")) {
          session_cache_file_rrmdir("{$dir}/{$file}");
        }
        else {
          unlink("{$dir}/{$file}");
        }
      }
    }
    return rmdir($dir);
  }
  return FALSE;
}