Rename (or move) a file

@access	public
@param	string
@return	bool
966880
function delete_file($filepath)
	{
		if ( ! $this->_is_conn())
		{
			return false;
		}

		$result = @ftp_delete($this->_conn_id, $filepath);

		if ($result === false)
		{
			if ($this->_debug == true)
			{
				throw new \FtpFileAccessException('Unable to delete');
			}
			return false;
		}

		return true;
	}
1130397
public function move($filename, $pathTo, $pathFrom = null)
    {
        if ($pathFrom==null) {
            $pathFrom=$this->_filePath;
        }
        if (file_exists($pathFrom."/".$filename)) {
            $this->createDir($pathTo);
            return rename($pathFrom."/".$filename, $pathTo."/".$filename);
        } else {
            return null;
        }
    }
473219
public function rename($path)
    {
        // This implementation supersedes the Flysystem's one. Indeed, while using connectors
        // such as the Amazon S3 (v3) connector, rename on directories does not work. A custom
        // implementation is then needed.
        $contents = $this->getFileSystem()->listContents($this->getPrefix(), true);

        // Filter files only.
        $filePaths = [];
        foreach ($contents as $content) {
            if ($content['type'] === 'file') {
                $filePaths[]= [
                    'source' => $content['path'],
                    'destination' => str_replace($this->getPrefix(), $path, $content['path'])];
            }
        }

        foreach ($filePaths as $renaming) {
            try {
                if ($this->getFileSystem()->rename($renaming['source'], $renaming['destination']) === false) {
                    throw new \common_exception_FileSystemError("Unable to rename '" . $this->getPrefix() . "' into '${path}'.");
                }
            } catch (FileExistsException $e) {
                throw new \common_exception_FileSystemError("Unable to rename '" . $this->getPrefix() . "' into '${path}'. File already exists.");
            }
        }

        if (!$this->deleteSelf()) {
            throw new \common_exception_FileSystemError("Could not finalize renaming of '" . $this->getPrefix() . "' into '${path}'.");
        }

        return true;
    }
855819
public function move($dest = '')
        {
            rename($this->getFilePath(), $dest);
            $this->setFilePath($dest);

            $this->capsule['filepath'] = $dest;
            return $this;
        }
965193
protected function _removeFile($file)
    {
        $_file = new File($file);

        if ($_file->exists()) {
            $_file->delete();

            $folder = $_file->folder();
            if (count($folder->find()) === 0) {
                $folder->delete();
            }
            return true;
        }
        return false;
    }
1107996
public function rename($oldPath, $newPath)
    {
        $old = $this->at($oldPath);
        $new = $this->at($newPath);

        if (null === $old || (null !== $new && 'dir' === $new->type))
            return false;

        if ('file' === $old->type) {
            $this->at($newPath, $old);
        } else {
            if (! $this->mkdir($newPath, $old->perms)) {
                return false;
            }
            $oldPath = $this->realpath($oldPath) . '/';
            $newPath = $this->realpath($newPath) . '/';
            $length = strlen($oldPath);
            foreach (array_keys($this->files) as $childPath) {
                if (substr($childPath, 0, $length) === $oldPath) {
                    $newChildPath = $newPath . substr($childPath, $length);
                    $this->at($newChildPath, $this->at($childPath));
                    $this->at($childPath, null);
                }
            }
        }
        $this->at($oldPath, null);
        return true;
    }
980708
private function rename(): RenameCommand
    {
        $name = $this->asksForApplicationName();

        if (File::exists($this->app->basePath($name))) {
            $this->app->abort(403, 'Folder or file already exists.');
        } else {
            $this->renameBinary($name)
                ->updateComposer($name);
        }

        return $this;
    }
1365687
public function renameFile($name, $newName)
    {
        foreach ($this->getAllFields() as $field) {
            $path = $this->getFilePath($field, $name);
            $newPath = $this->getFilePath($field, $newName);
            if (file_exists($newPath)) {
                throw new \Exception("File {$newName} already exists");
            }
            rename($path, $newPath);
        }
        if ($name == $this->owner->getAttribute($this->fileField)
            && ($files = $this->getFileList())
        ) {
            $this->owner->updateAttributes([$this->fileField => $newName]);
        }
        return true;
    }
555001
public function rename($oldname, $newname)
    {
        $this->copy($oldname, $newname);

        // Delete the original object
        if ($this->isDir($oldname))
        {
            $this->deleteFolder($oldname);
        } else {
            $this->delete($oldname);
        }

        return true;
    }
112365
public function moveDirectory( $from, $to, $overwrite = false ): bool
	{
		if( $overwrite && $this->isDirectory( $to ) && ! $this->deleteDirectory( $to ) )
		{
			return false;
		}
		return @ rename( $from, $to ) === true;
	}
221682
function cmd_RNTO($fd, $cmd)
    {
        $user = $this->getUser($fd);
        $old_file = $this->users[$user]['rename'];
        $new_file = $this->fillDirName($user, $cmd[1]);
        $this->debug("RENAME: $old_file to $new_file");
        if (empty($old_file) or !is_dir(dirname($new_file)))
        {
            $this->send($fd, "451 Rename/move failure: No such file or directory");
        }
        elseif (rename($old_file, $new_file))
        {
            $this->send($fd, "250 File successfully renamed or moved");
        }
        else
        {
            $this->send($fd, "451 Rename/move failure: Operation not permitted");
        }
        unset($this->users[$user]['rename']);
    }
344073
public static function move($source, $des)
    {
        if (!is_file($source)) {
            return false;
        }
        try {
            @rename($source, $des);
            return true;
        } catch (\Exception $e) {
            return false;
        }
    }
475115
public function move($path, $overwrite = false) {
        $path = str_replace('\\', '/', $path);

        if (substr($path, -1) !== '/') {
            $path .= '/';
        }

        // Don't move to the same folder
        if (realpath($path) === realpath($this->dir())) {
            return true;
        }

        if (!file_exists($path)) {
            mkdir($path, 0777, true);

        } else if (!is_writable($path)) {
            chmod($path, 0777);
        }

        // Determine name and overwrite
        $name = $this->name();
        $ext = $this->ext();

        if (!$overwrite) {
            $no = 1;

            while (file_exists($path . $name . '.' . $ext)) {
                $name = $this->name() . '-' . $no;
                $no++;
            }
        }

        // Move the file
        $targetPath = $path . $name . '.' . $ext;

        if (rename($this->path(), $targetPath)) {
            $this->reset($targetPath);

            return true;
        }

        return false;
    }
1140414
public function moveUploadedFile($filename, $dest)
    {
        if (!$this->isUploadedFile($filename)) {
            return false;
        }
        return FileSystem::rename($filename, $dest);
    }
104215
public function moveFile($currentFile, $newFile)
    {
        if ($this->disk->exists($newFile)) {
            $this->errors[] = 'File already exists.';

            return false;
        }

        return $this->disk->getDriver()->rename($currentFile, $newFile);
    }
939331
function renameFile (oldFile, newFile) {
    if (!isFileRegistered(oldFile) || isFileRegistered(newFile)) { return undefined; }

    let item = fileRegistry[oldFile];

    item.file = newFile;

    fileRegistry[newFile] = item;

    delete fileRegistry[oldFile];
}
949704
public function renameFile(Request $request)
    {
        $namespace = $request->request->get('namespace');
        $parent = $request->request->get('parent');
        $oldName = $request->request->get('oldname');
        $newName = $request->request->get('newname');

        if (!$this->isExtensionChangedAndIsChangeAllowed($oldName, $newName)) {
            return $this->json(Trans::__('general.phrase.only-root-change-file-extensions'), Response::HTTP_FORBIDDEN);
        }

        if ($this->validateFileExtension($newName) === false) {
            return $this->json(
                sprintf("File extension not allowed: %s", $newName),
                Response::HTTP_BAD_REQUEST
            );
        }

        try {
            $this->filesystem()->rename("$namespace://$parent/$oldName", "$parent/$newName");

            return $this->json($newName, Response::HTTP_OK);
        } catch (ExceptionInterface $e) {
            $msg = Trans::__('Unable to rename file: %FILE%', ['%FILE%' => $oldName]);
            $this->logException($msg, $e);

            if ($e instanceof FileExistsException) {
                $status = Response::HTTP_CONFLICT;
            } elseif ($e instanceof FileNotFoundException) {
                $status = Response::HTTP_NOT_FOUND;
            } else {
                $status = Response::HTTP_INTERNAL_SERVER_ERROR;
            }

            return $this->json($msg, $status);
        }
    }