You are here

function coder_upgrade_clean_directory in Coder 7

Same name and namespace in other branches
  1. 7.2 coder_upgrade/coder_upgrade.inc \coder_upgrade_clean_directory()

Removes all files from a directory and optionally removes the directory.

Parameters

string $path Directory path.:

2 calls to coder_upgrade_clean_directory()
coder_upgrade_convert_dir in coder_upgrade/includes/main.inc
Converts files in a directory.
coder_upgrade_uninstall in coder_upgrade/coder_upgrade.install
Implements hook_uninstall().

File

coder_upgrade/coder_upgrade.inc, line 72
Provides constants and utility functions.

Code

function coder_upgrade_clean_directory($path, $remove_me = FALSE) {
  $path = $path . '/';
  if (!is_dir($path)) {
    return;
  }
  $files = scandir($path);
  foreach ($files as $file) {
    if ($file != '.' && $file != '..') {
      $file_path = $path . $file;
      if (is_dir($file_path)) {
        coder_upgrade_clean_directory($file_path, TRUE);
      }
      else {
        file_unmanaged_delete($file_path);
      }
    }
  }
  if ($remove_me) {
    rmdir($path);
  }
}