本文整理汇总了PHP中PhingFile::renameTo方法的典型用法代码示例。如果您正苦于以下问题:PHP PhingFile::renameTo方法的具体用法?PHP PhingFile::renameTo怎么用?PHP PhingFile::renameTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhingFile
的用法示例。
在下文中一共展示了PhingFile::renameTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renameFile
/**
* Attempts to rename a file from a source to a destination.
* If overwrite is set to true, this method overwrites existing file
* even if the destination file is newer.
* Otherwise, the source f
* ile is renamed only if the destination file #
* is older than it.
*/
private function renameFile(PhingFile $sourceFile, PhingFile $destFile, $overwrite)
{
$renamed = true;
// ensure that parent dir of dest file exists!
$parent = $destFile->getParentFile();
if ($parent !== null) {
if (!$parent->exists()) {
$parent->mkdirs();
}
}
if ($destFile->exists()) {
try {
$destFile->delete();
} catch (Exception $e) {
throw new BuildException("Unable to remove existing file " . $destFile->__toString() . ": " . $e->getMessage());
}
}
$renamed = $sourceFile->renameTo($destFile);
return $renamed;
}