You are here

public function DirectoryOperations::directoryRecursiveCopy in AT Tools 8

Same name and namespace in other branches
  1. 8.3 at_theme_generator/src/File/DirectoryOperations.php \Drupal\at_theme_generator\File\DirectoryOperations::directoryRecursiveCopy()
  2. 8.2 at_theme_generator/src/File/DirectoryOperations.php \Drupal\at_theme_generator\File\DirectoryOperations::directoryRecursiveCopy()

Copy a directory recursively.

Parameters

$source: The source directory.

$target: The target directory.

$ignore: Regex to filter out unwanted files and directories.

File

at_theme_generator/src/File/DirectoryOperations.php, line 39
Contains \Drupal\at_theme_generator\File\DirectoryOperations

Class

DirectoryOperations

Namespace

Drupal\at_theme_generator\File

Code

public function directoryRecursiveCopy($source, $target, $ignore = '/^(\\.(\\.)?|CVS|\\.sass-cache|\\.svn|\\.git|\\.DS_Store)$/') {
  $dir = opendir($source);
  @mkdir($target);
  while ($file = readdir($dir)) {
    if (!preg_match($ignore, $file)) {
      if (is_dir($source . '/' . $file)) {
        self::directoryRecursiveCopy($source . '/' . $file, $target . '/' . $file, $ignore);
      }
      else {
        copy($source . '/' . $file, $target . '/' . $file);
      }
    }
  }
  closedir($dir);
}