/** * Retrieves the container folder and optionally creates a new folder if required. * @param Directory The base path to use * @param string The name of the container. Uses the first CONTAINER_NAME_USAGE_LENGTH characters of the string. If the string is smaller, Its get zero-padded. * @param bool True to create the folder if it does not exists, false otherwise. * @return Directory Returns the requested path with the container components */ protected static function getContainerFolder(\System\IO\Directory $baseFolder, $container, $createIfNotExists) { $containerNameUsage = self::getContainerNameParts($container); $containerNameParts = str_split($containerNameUsage); $containerPath = implode(\System\IO\Directory::getSeparator(), $containerNameParts); $basePath = new \System\IO\Directory($baseFolder->getCurrentPath() . $containerPath, false); if (!$basePath->exists() && $createIfNotExists) { $oldMask = umask(0); mkdir($basePath->getCurrentPath(), \System\IO\Directory::FULL_ACCESS, true); umask($oldMask); } if (!$basePath->exists()) { throw new \System\Error\Exception\FileNotFoundException('Could not create the given folder: ' . $basePath->getCurrentPath()); } return $basePath; }
private static final function copyFiles(\System\IO\Directory $targetFolder, $sourceFolder, \System\Collection\Vector $fileMask, $baseSubfolder) { $files = \System\IO\Directory::walkDir($sourceFolder, $fileMask); $target = new \System\IO\Directory($targetFolder->getCurrentPath() . \System\IO\Directory::getSeparator() . $baseSubfolder); foreach ($files as $file) { $baseFile = $file->stripBase($sourceFolder); $folderParts = preg_split('/\\\\/', $baseFile); array_pop($folderParts); $newPath = $target->getCurrentPath(); foreach ($folderParts as $part) { $newPath = \System\IO\Directory::getPath($newPath . \System\IO\Directory::getSeparator() . $part); if (!file_exists($newPath)) { mkdir($newPath, 0777, true); } } $newPath .= \System\IO\Directory::getSeparator() . $file->getFilename(); $file->copyFile($newPath); } }