How can PHP be used to rename directories?
To rename directories using PHP, you can use the `rename()` function. This function takes two parameters: the current directory name and the new directory name. Make sure the current directory exists and the new directory name is unique to avoid conflicts.
$oldDir = 'old_directory';
$newDir = 'new_directory';
if (file_exists($oldDir)) {
if (rename($oldDir, $newDir)) {
echo 'Directory renamed successfully.';
} else {
echo 'Error renaming directory.';
}
} else {
echo 'Directory does not exist.';
}
Keywords
Related Questions
- What resources or documentation should be consulted when working with PHP functions like time() and date()?
- What are the potential pitfalls of using preg_replace for string manipulation in PHP?
- What are some common mistakes or misconceptions beginners might have when trying to implement PHP functions for password generation?