- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/classes/general/virtual_io_filesystem.php
- Класс: CBXVirtualIoFileSystem
- Вызов: CBXVirtualIoFileSystem::CopyDirFiles
private function CopyDirFiles($pathFrom, $pathTo, $bRewrite = true, $bDeleteAfterCopy = false)
{
$this->ClearErrors();
if (mb_strpos($pathTo."/", $pathFrom."/") === 0)
{
$this->AddError("Can not copy a file onto itself");
return false;
}
$pathFromEncoded = CBXVirtualIoFileSystem::ConvertCharset($pathFrom);
if (is_dir($pathFromEncoded))
{
$this->CreateDirectory($pathTo);
}
elseif (is_file($pathFromEncoded))
{
$this->CreateDirectory($this->ExtractPathFromPath($pathTo));
$pathToEncoded = CBXVirtualIoFileSystem::ConvertCharset($pathTo);
if (file_exists($pathToEncoded) && !$bRewrite)
{
$this->AddError(sprintf("The file '%s' already exists", $pathTo));
return false;
}
@copy($pathFromEncoded, $pathToEncoded);
if (is_file($pathToEncoded))
{
@chmod($pathToEncoded, BX_FILE_PERMISSIONS);
if ($bDeleteAfterCopy)
@unlink($pathFromEncoded);
}
else
{
$this->AddError(sprintf("Creation of file '%s' failed", $pathTo));
return false;
}
return true;
}
else
{
return true;
}
$pathToEncoded = CBXVirtualIoFileSystem::ConvertCharset($pathTo);
if ($handle = @opendir($pathFromEncoded))
{
while (($file = readdir($handle)) !== false)
{
if ($file == "." || $file == "..")
continue;
if (is_dir($pathFromEncoded."/".$file))
{
$pathFromDecodedTmp = CBXVirtualIoFileSystem::ConvertCharset($pathFromEncoded."/".$file, CBXVirtualIoFileSystem::directionDecode);
$pathToDecodedTmp = CBXVirtualIoFileSystem::ConvertCharset($pathToEncoded."/".$file, CBXVirtualIoFileSystem::directionDecode);
CopyDirFiles($pathFromDecodedTmp, $pathToDecodedTmp, $bRewrite, $bDeleteAfterCopy);
if ($bDeleteAfterCopy)
@rmdir($pathFromEncoded."/".$file);
}
elseif (is_file($pathFromEncoded."/".$file))
{
if (file_exists($pathToEncoded."/".$file) && !$bRewrite)
continue;
@copy($pathFromEncoded."/".$file, $pathToEncoded."/".$file);
@chmod($pathToEncoded."/".$file, BX_FILE_PERMISSIONS);
if ($bDeleteAfterCopy)
@unlink($pathFromEncoded."/".$file);
}
}
@closedir($handle);
if ($bDeleteAfterCopy)
@rmdir($pathFromEncoded);
return true;
}
$this->AddError(sprintf("Can not open directory '%s'", $pathFrom));
return false;
}