Search code examples
phprenameshortcut

How to make a copy when using rename() command?


Hello so I have this piece of code

$old_name = "C:\\inetpub\\users\\john\\cars.properties";
$new_name = "toys.properties";

rename($old_name, $new_name) ;

It changes the name of cars.properties to toys.properties but I dont really want to change the original cars.properties file, is it possible to the code itself can make a copy instead of me making a shortcut? If so I would really appreciate it!


Solution

  • @phpscrub simply by setting it this way:

    $old_name = "C:\\inetpub\\users\\john\\cars.properties";
    $new_name = "C:\\inetpub\\users\\john\\toys.properties";
    
    // copy and rename at same time ;-)
    copy($old_name, $new_name);
    

    so the cars.properties file will be copied to the new file renamed toys.properties