• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/zip.php
  • Класс: CZip
  • Вызов: CZip::_addFileList
private function _addFileList($arFilesList, &$arResultList, $addDir, $removeDir, $removeAllDir, &$arParams)
{
	$res = 1;
	$header = [];

	//save the current number of elements in the result list
	$count = sizeof($arResultList);
	$filesListCount = count($arFilesList);
	for ($j = 0; ($j < $filesListCount) && ($res == 1); $j++)
	{
		$filename = $this->_convertWinPath($arFilesList[$j], false);

		//if empty - skip
		if ($filename == "")
		{
			continue;
		}

		if (!file_exists($this->io->GetPhysicalName($filename)))
		{
			$this->_errorLog("ERR_MISSING_FILE", str_replace("#FILE_NAME#", removeDocRoot($filename), GetMessage("MAIN_ZIP_ERR_MISSING_FILE")));
			return $this->arErrors;
		}

		if ((is_file($this->io->GetPhysicalName($filename))) || ((is_dir($this->io->GetPhysicalName($filename))) && !$removeAllDir))
		{
			if (($res = $this->_addFile($filename, $header, $addDir, $removeDir, $removeAllDir, $arParams)) != 1)
			{
				return $res;
			}

			//save file info
			$arResultList[$count++] = $header;
		}

		if (is_dir($this->io->GetPhysicalName($filename)))
		{
			if ($filename != ".")
			{
				$path = $filename . "/";
			}
			else
			{
				$path = "";
			}

			//read the folder for files and subfolders
			$hdir = opendir($this->io->GetPhysicalName($filename));

			while ($hitem = readdir($hdir))
			{
				if ($hitem == '.' || $hitem == '..')
				{
					continue;
				}

				if (is_file($this->io->GetPhysicalName($path . $hitem)))
				{
					if (($res = $this->_addFile($path . $hitem, $header, $addDir, $removeDir, $removeAllDir, $arParams)) != 1)
					{
						return $res;
					}
					//save file info
					$arResultList[$count++] = $header;
				}
				else
				{
					//should be ana array as a parameter
					$arTmpList[0] = $path . $hitem;

					$res = $this->_addFileList($arTmpList, $arResultList, $addDir, $removeDir, $removeAllDir, $arParams);
					$count = sizeof($arResultList);
				}
			}

			//unset variables for the recursive call
			unset($arTmpList);
			unset($hdir);
			unset($hitem);
		}
	}

	return $res;
}