【问题标题】:How to make a copy when using rename() command?使用 rename() 命令时如何制作副本?
【发布时间】:2020-06-22 11:10:15
【问题描述】:

你好,我有这段代码

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

rename($old_name, $new_name) ;

它将cars.properties 的名称更改为toys.properties,但我真的不想更改原始的cars.properties 文件,代码本身是否可以复制而不是我制作快捷方式?如果是这样,我将不胜感激!

【问题讨论】:

标签: php rename shortcut


【解决方案1】:

@phpscrub 只需这样设置:

$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);

因此cars.properties 文件将被复制到重命名为toys.properties 的新文件中

【讨论】:

  • 我已经通过这样做找到了它;重命名(复制($old_name,$new_name));无论如何谢谢:)
  • 好的,但只需 copy($old_name,$ new_name) 就足够了,因为您使用新名称将其分配给 $ new_name 并且已经复制了相同的文件并重命名。 ;-)
猜你喜欢
  • 2019-12-15
  • 1970-01-01
  • 1970-01-01
  • 2016-02-24
  • 1970-01-01
  • 1970-01-01
  • 2019-10-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多