function drush_move_dir

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

Move $src to $dest.

If the php 'rename' function doesn't work, then we'll do copy & delete.


$src: The directory to move.

$dest: The destination to move the source to, including the new name of the directory. To move directory "a" from "/b" to "/c", then $src = "/b/a" and $dest = "/c/a". To move "a" to "/c" and rename it to "d", then $dest = "/c/d" (just like php rename function).

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

Return value

TRUE on success, FALSE on failure.

Related topics

12 calls to drush_move_dir()
drush_archive_dump in commands/core/
Command callback. Generate site archive file.
drush_archive_restore in commands/core/
Command callback. Restore web site(s) from a site archive file.
drush_version_control_backup::pre_update in commands/pm/version_control/
Implementation of pre_update().
drush_version_control_backup::rollback in commands/pm/version_control/
Implementation of rollback().
make_download_file_unpack in commands/make/
Unpacks a file to the specified download location.

... See full list


includes/, line 306
Filesystem utilities.


function drush_move_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 rename. It will fail if $src and $dest are not in the same partition.
  if (@drush_op('rename', $src, $dest)) {
    return TRUE;
  // Eventually it will create an empty file in $dest. See
  elseif (is_file($dest)) {
    drush_op('unlink', $dest);

  // If 'rename' fails, then we will use copy followed
  // by a delete of the source.
  if (drush_copy_dir($src, $dest)) {
    drush_op('drush_delete_dir', $src, TRUE);
    return TRUE;

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