You are here

public function DirectoryOperations::directoryRecursiveCopy in AT Tool 2.0 1.0.x

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 41

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);

  /*file_prepare_directory($target, FILE_CREATE_DIRECTORY);*/
  \Drupal::service('file_system')
    ->prepareDirectory($target, FileSystemInterface::CREATE_DIRECTORY);
  while ($file = readdir($dir)) {
    if (!preg_match($ignore, $file)) {
      if (is_dir($source . '/' . $file)) {
        self::directoryRecursiveCopy($source . '/' . $file, $target . '/' . $file, $ignore);
      }
      else {

        /*file_unmanaged_copy($source . '/' . $file, $target . '/' . $file, FILE_EXISTS_RENAME);*/
        \Drupal::service('file_system')
          ->copy($source . '/' . $file, $target . '/' . $file, FileSystemInterface::EXISTS_RENAME);
      }
    }
  }
  closedir($dir);
}