36 $tempDirPath = \CTempFile::getDirectoryName($timeToLive, array($prefix, \uniqid($prefix,
true)));
37 $tempDir =
new static($tempDirPath);
38 if (!$tempDir->isExists())
62 bool $recursive =
false,
63 bool $convertEncoding =
false,
64 string $sourceEncoding =
'',
65 string $targetEncoding =
''
68 if (\mb_strpos($target->getPhysicalPath(), $this->getPhysicalPath()) === 0)
70 $this->addError(
new Main\
Error(
'Destination is inside in the source folder.'));
76 $this->addError(
new Main\
Error(
'Source is not exists.'));
80 if (!$target->isExists())
90 foreach ($children as $entry)
92 if (in_array($entry->getName(), Translate\IGNORE_FS_NAMES,
true))
98 ($entry instanceof Main\
IO\Directory) &&
99 $entry->isDirectory() &&
103 $source =
new self($entry->getPhysicalPath());
104 $res = $source->copy(
105 (
new Main\
IO\Directory($target->getPhysicalPath().
'/'. $entry->getName())),
120 ($entry instanceof Main\
IO\File) &&
124 $file =
new Main\IO\File($target->getPhysicalPath().
'/'. $entry->getName());
125 if ($file->isExists() && !$reWrite)
132 $content = $entry->getContents();
133 $content = \str_replace(array(
"\r\n",
"\r"), array(
"\n",
"\n"), $content);
135 if ($convertEncoding)
137 $content = \Bitrix\Main\Text\Encoding::convertEncoding($content, $sourceEncoding, $targetEncoding);
140 $file->putContents($content);
142 catch (Main\
IO\IoException $exception)
165 public function copyLangOnly(
166 Main\
IO\Directory $target,
168 bool $convertEncoding =
false,
169 string $sourceEncoding =
'',
170 string $targetEncoding =
''
173 if (mb_strpos($target->getPhysicalPath(), $this->getPhysicalPath()) === 0)
175 $this->
addError(
new Main\
Error(
'Destination is inside in the source folder.'));
191 foreach ($children as $dir)
193 $dirName = $dir->getName();
195 !$dir instanceof Main\
IO\Directory ||
196 !$dir->isDirectory() ||
197 \in_array($dirName, Translate\IGNORE_FS_NAMES,
true)
203 if ($dirName ===
'lang' || $dirName ===
'payment')
205 $source =
new self($dir->getPhysicalPath().
'/'. $languageId);
206 if ($source->isExists())
208 if (!$target->isExists())
212 $targetDir = $target->createSubdirectory($dirName)->createSubdirectory($languageId);
214 $res = $source->copy(
231 $source =
new self($dir->getPhysicalPath());
232 $res = $source->copyLangOnly(
233 (
new Main\
IO\Directory($target->getPhysicalPath().
'/'. $dirName)),
258 public function wipe(?\Closure $filter =
null): bool
272 foreach ($children as $entry)
274 if ($filter instanceof \Closure)
276 if ($filter($entry) !==
true)
281 $result = $entry->delete();