Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Filesystem.php

function Filesystem::rename

Same name in this branch
  1. 11.1.x vendor/composer/composer/src/Composer/Util/Filesystem.php \Composer\Util\Filesystem::rename()

Renames a file or a directory.

Throws

IOException When target file or directory already exists

IOException When origin cannot be renamed

1 call to Filesystem::rename()
Filesystem::dumpFile in vendor/symfony/filesystem/Filesystem.php
Atomically dumps content into a file.

File

vendor/symfony/filesystem/Filesystem.php, line 289

Class

Filesystem
Provides basic utility to manipulate the file system.

Namespace

Symfony\Component\Filesystem

Code

public function rename(string $origin, string $target, bool $overwrite = false) : void {
    // we check that target does not exist
    if (!$overwrite && $this->isReadable($target)) {
        throw new IOException(\sprintf('Cannot rename because the target "%s" already exists.', $target), 0, null, $target);
    }
    if (!self::box('rename', $origin, $target)) {
        if (is_dir($origin)) {
            // See https://bugs.php.net/54097 & https://php.net/rename#113943
            $this->mirror($origin, $target, null, [
                'override' => $overwrite,
                'delete' => $overwrite,
            ]);
            $this->remove($origin);
            return;
        }
        throw new IOException(\sprintf('Cannot rename "%s" to "%s": ', $origin, $target) . self::$lastError, 0, null, $target);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal