function drush_copy_dir

8.0.x drush_copy_dir($src, $dest, $overwrite = FILE_EXISTS_ABORT)
6.x drush_copy_dir($src, $dest, $overwrite = FILE_EXISTS_ABORT)
7.x drush_copy_dir($src, $dest, $overwrite = FILE_EXISTS_ABORT)
4.x drush_copy_dir($src, $dest, $overwrite = FALSE)
5.x drush_copy_dir($src, $dest, $overwrite = FILE_EXISTS_ABORT)
master drush_copy_dir($src, $dest, $overwrite = FILE_EXISTS_ABORT)

Copy $src to $dest.


$src: The directory to copy.

$dest: The destination to copy the source to, including the new name of the directory. To copy directory "a" from "/b" to "/c", then $src = "/b/a" and $dest = "/c/a". To copy "a" to "/c" and rename it to "d", then $dest = "/c/d".

$overwrite: If TRUE, the destination will be deleted if it exists.

Return value

TRUE on success, FALSE on failure.

Related topics

3 calls to drush_copy_dir()
drush_move_dir in includes/
Move $src to $dest.
drush_pm_version_control_backup::pre_update in commands/pm/version_control/
Implementation of pre_update().
drush_tarball_extract in includes/
Extract a tarball.


includes/, line 1658
The drush API implementation and helpers.


function drush_copy_dir($src, $dest, $overwrite = FALSE) {
  // Preflight based on $overwrite if $dest exists.
  if (file_exists($dest)) {
    if ($overwrite) {
      drush_op('drush_delete_dir', $dest, TRUE);
    else {
      return drush_set_error('DRUSH_DESTINATION_EXISTS', dt('Destination directory !dest already exists.', array('!dest' => $dest)));
  // $src readable?
  if (!drush_op('is_readable', $src)) {
    return drush_set_error('DRUSH_SOURCE_NOT_EXISTS', dt('Source directory !src is not readable or does not exist.', array('!src' => $src)));
  // $dest writable?
  if (!drush_op('is_writable', dirname($dest))) {
    return drush_set_error('DRUSH_DESTINATION_NOT_WRITABLE', dt('Destination directory !dest is not writable.', array('!dest' => dirname($dest))));
  // Try to do a recursive copy.
  if (@drush_op('_drush_recursive_copy', $src, $dest)) {
    return TRUE;

  return drush_set_error('DRUSH_COPY_DIR_FAILURE', dt('Unable to copy !src to !dest.', array('src' => $src, 'dest' => $dest)));