You are here

function xmlsitemap_directory_move in XML sitemap 7.2

Same name and namespace in other branches
  1. 8 xmlsitemap.module \xmlsitemap_directory_move()
  2. 6.2 xmlsitemap.module \xmlsitemap_directory_move()
  3. 2.x xmlsitemap.module \xmlsitemap_directory_move()

Move a directory to a new location.


string $old_dir: A string specifying the filepath or URI of the original directory.

string $new_dir: A string specifying the filepath or URI of the new directory.

string $replace: Replace behavior when the destination file already exists.

Return value

bool TRUE if the directory was moved successfully. FALSE otherwise.

1 call to xmlsitemap_directory_move()
xmlsitemap_sitemap_save in ./xmlsitemap.module
Save changes to an XML sitemap or add a new XML sitemap.


./xmlsitemap.module, line 950
xmlsitemap XML sitemap


function xmlsitemap_directory_move($old_dir, $new_dir, $replace = FILE_EXISTS_REPLACE) {
  $success = file_prepare_directory($new_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
  $old_path = drupal_realpath($old_dir);
  $new_path = drupal_realpath($new_dir);
  if (!is_dir($old_path) || !is_dir($new_path) || !$success) {
    return FALSE;
  $files = file_scan_directory($old_dir, '/.*/');
  foreach ($files as $file) {
    $file->uri_new = $new_dir . '/' . basename($file->filename);
    $success &= (bool) file_unmanaged_move($file->uri, $file->uri_new, $replace);

  // The remove the directory.
  $success &= drupal_rmdir($old_dir);
  return $success;