Oihana PHP

renameFile.php

Table of Contents

Functions

renameFile()  : bool
Renames a single file.

Functions

renameFile()

Renames a single file.

renameFile(string $source, string $destination[, bool $overwrite = true ][, bool $createDirectory = true ]) : bool

Semantic alias of moveFile(): renaming a file is the same operation as moving it (the destination may be a new name in the same directory, a path in another directory, or an existing directory to move into). See moveFile() for the full destination, overwrite and cross-filesystem semantics.

Parameters
$source : string

Path to the source file to rename.

$destination : string

New file path, or an existing directory to move into.

$overwrite : bool = true

Whether to overwrite an existing destination file (default: true).

$createDirectory : bool = true

Whether to create the destination directory if missing (default: true).

Tags
throws
FileException

If the source is invalid, or the destination exists and $overwrite is false.

DirectoryException

If the destination directory is missing and $createDirectory is false, or cannot be created.

author

Marc Alcaraz (ekameleon)

since
1.2.0
example
use function oihana\files\renameFile;

renameFile( '/data/old-name.txt' , '/data/new-name.txt' ) ;
Return values
bool

Returns true on success.

On this page

Search results