$old_name = '/path/to/old/file.txt'; $new_name = '/path/to/new/file.txt'; if (rename($old_name, $new_name)) { echo "File renamed successfully."; } else { echo "Error renaming file."; }
$old_name = '/path/to/old/directory'; $new_name = '/path/to/new/directory'; if (rename($old_name, $new_name)) { echo "Directory renamed successfully."; } else { echo "Error renaming directory."; }This code renames the directory located at "/path/to/old/directory" to "/path/to/new/directory". If the rename is successful, it will output "Directory renamed successfully." Otherwise, it will output "Error renaming directory."