Creates a new collection (folder) at the given path $target.

@param string $target Eg. '/plain_site_user/Content/Folder1'
@return bool
547423
protected function createCollection( $target )
    {
        $target = $this->splitFirstPathElement( $target, $currentSite );

        if ( !$currentSite )
        {
            // Site list cannot get new entries
            return false; // @as self::FAILED_FORBIDDEN;
        }

        return $this->mkcolVirtualFolder( $currentSite, $target );
    }
959821
private function copyThenRemove($source, $target)
    {
        if (!is_dir($source)) {
            copy($source, $target);
            $this->unlink($source);

            return;
        }

        $it = new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS);
        $ri = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::SELF_FIRST);
        $this->ensureDirectoryExists($target);

        foreach ($ri as $file) {
            $targetPath = $target.DIRECTORY_SEPARATOR.$ri->getSubPathName();
            if ($file->isDir()) {
                $this->ensureDirectoryExists($targetPath);
            } else {
                copy($file->getPathname(), $targetPath);
            }
        }

        $this->removeDirectoryPhp($source);
    }
120204
public function deleteFiles($target)
    {
        if (is_dir($target)) {
            $files = glob($target . '*', GLOB_MARK); //GLOB_MARK adds a slash to directories returned

            foreach ($files as $file) {
                $this->deleteFiles($file);
            }

            if (is_dir($target)) {
                rmdir($target);
            }

        } elseif (is_file($target)) {
            unlink($target);
        }
    }
508003
public function files($paths = false, $createMissing = false)
    {
        if ($paths === false) {
            return $this->find('*')->files();
        }

        $list = new Collection;
        foreach ($paths as $path) {
            $list->add($this->file($path, $createMissing));
        }
        return $list;
    }
729458
public function podiumMoveTo($target = null)
    {
        $newParent = Forum::find()->where(['id' => $target])->limit(1)->one();
        if (empty($newParent)) {
            Log::error('No parent forum of given ID found', $this->id, __METHOD__);
            return false;
        }

        $postsCount = $this->postsCount;
        $transaction = Forum::getDb()->beginTransaction();
        try {
            $this->forum->updateCounters(['threads' => -1, 'posts' => -$postsCount]);
            $newParent->updateCounters(['threads' => 1, 'posts' => $postsCount]);
            $this->forum_id = $newParent->id;
            $this->category_id = $newParent->category_id;
            if (!$this->save()) {
                throw new Exception('Thread saving error!');
            }
            Post::updateAll(['forum_id' => $newParent->id], ['thread_id' => $this->id]);
            $transaction->commit();
            PodiumCache::clearAfter('threadMove');
            Log::info('Thread moved', $this->id, __METHOD__);
            return true;
        } catch (Exception $e) {
            $transaction->rollBack();
            Log::error($e->getMessage(), null, __METHOD__);
        }
        return false;
    }
703215
protected function addItemToTarget(array &$target, array $item, $first=false, $createGroup=false)
	{
		if(is_array($item['attributes'])) {
			$attributes = '';

			foreach($item['attributes'] as $attribute) {
				// do not assign empty attributes
				if($attribute['name'] == '') {
					continue;
				}

				if($attribute['name'] == 'class' && !isset($item['class'])) {
					$item['class'] = $attribute ['value'];
					continue;
				}

				$attributes .= $attributes ? ' ' : '';
				$attributes .= $attribute['name'] . '="' . $attribute ['value'] . '"';

			}

			$item['attributes'] = $attributes;
		}

		// make sure every key is set
		$item = array_merge(array(
				'type'      => '',
				'button'    => 'link',
				'attributes'=> '',
				'url'       => '',
				'label'     => ''
			), $item
		);


		if($first)
		{
			if($createGroup && isset($target[0]) && $target[0]['type'] == 'group')
			{
				$item = array('type' => 'group', 'items' => array($item));
			}

			$target = array_merge(array($item), $target);
			return;
		}

		if($createGroup)
		{
			$end = end($this->arrButtons);

			if($end !== false && $end['type'] == 'group')
			{
				$item = array('type' => 'group', 'items' => array($item));
			}
		}

		$target[] = $item;
	}
1090054
public static function copy($source, $target, $ignore = null)
    {
        $source = rtrim($source, '\\/');
        $target = rtrim($target, '\\/');

        if (!is_dir($source)) {
            throw new \RuntimeException('Cannot copy non-existing folder.');
        }

        // Make sure that path to the target exists before copying.
        self::create($target);

        $success = true;

        // Go through all sub-directories and copy everything.
        $files = self::all($source);
        foreach ($files as $file) {
            if ($ignore && preg_match($ignore, $file)) {
                continue;
            }
            $src = $source .'/'. $file;
            $dst = $target .'/'. $file;

            if (is_dir($src)) {
                // Create current directory (if it doesn't exist).
                if (!is_dir($dst)) {
                    $success &= @mkdir($dst, 0777, true);
                }
            } else {
                // Or copy current file.
                $success &= @copy($src, $dst);
            }
        }

        if (!$success) {
            $error = error_get_last();
            throw new \RuntimeException($error['message'] ?? 'Unknown error');
        }

        // Make sure that the change will be detected when caching.
        @touch(dirname($target));
    }
556956
public function copyDir($source, $target, $dir)
    {
        $this->mkDir($target);
        $serverOs = (new \Zest\Common\OperatingSystem())->get();
        $command = ($serverOs === 'Windows') ? 'xcopy ' : 'cp -r ';
        if (is_dir($source.$dir)) {
            shell_exec($command.$source.$dir.' '.$target);
        }
    }
309837
public function upload($path, $target)
	{
		$success = false;

		$dir = dirname($target);

		if (!is_dir($dir))
		{
			if (!$this->makeDirectory($dir))
			{
				return $success;
			}
		}

		if (is_writeable($dir) && move_uploaded_file($path, $target))
		{
			if ($this->setPermissions($target))
			{
				$success = true;
			}
		}

		return $success;
	}
981892
public function download($url, $target, $callback = null)
    {
        if (!$this->filesystem->fileExists($target)) {
            $this->filesystem->dirCreate(dir($target));

            $request = new Request($url, $callback ?: function ($response) {
            });

            $request->options['file'] = $target;

            $this->add($request);
        }

        return $this;
    }
38126
public function hasKey($target)
    {
        foreach ($this->collection as $group => $hashMap) {
            if (array_key_exists($target, $hashMap)) {
                return true;
            }
        }

        // By default
        return false;
    }
327288
static function copyDirectory($source, $target, $overwrite = true)
    {
        $scanResult = static::scanDirectory($source);
        if (!$scanResult) return false;
        if (!is_dir($target)) self::createDirectory($target);

        try {
            $sourceRealPath = realpath($source);
            foreach ($scanResult['files'] as $file) {
                $targetRealPath = realpath($target) . '/' . ltrim(substr($file, strlen($sourceRealPath)), '/');
                static::copyFile($file, $targetRealPath, $overwrite);
            }
            return true;
        } catch (\Throwable $throwable) {
            return false;
        }
    }
289385
protected static function createLink( $source, $target )
	{
		if( file_exists( $target ) === false && @symlink( $source, $target ) === false )
		{
			$source = realpath( __DIR__ . '/' . $source );

			if( symlink( $source, $target ) === false ) {
				throw new \RuntimeException( sprintf( 'Failed to create symlink for "%1$s" to "%2$s"', $source, $target ) );
			}
		}
	}
279039
public function copy($target) {
        if (!parent::copy($target))
            return false;
        return copy($this->fileSource, $target);
    }
637109
static function copyDirectoryContents($dir, $target, $overwrite = true, $base = '')
	{
		$dir = rtrim($dir, "\\/ ").'/';
		$target = rtrim($target, "\\/ ").'/';
		$report = ['error'=>[],'copied'=>[]];

		if (!static::checkAndOrCreateDir($target, true, 0777)) {
			$report['error']['permission'] = $taget;
			return $report;
		}

		foreach (scandir($dir) as $file) {
			if ($file == '.' || $file == '..') {
				continue;
			}

			if (is_dir($dir.$file)) {
				if (!static::checkAndOrCreateDir($target.$file, true, 0777)) {
					$report['error']['permission'] = $taget.$file;
					return $report;
				} else {
					$copy = static::copyDirectoryContents($dir.$file, $target.$file, $overwrite, $base);
					$report = array_merge_recursive($report, $copy);
				}
			} elseif (is_file($dir.$file)) {
				if ($overwrite === false && file_exists($target.$file)) {
					$report['error']['overwrite'][] = str_replace($base.'/', '', $target.$file);
					continue;
				}
				if (!copy($dir.$file, $target.$file)) {
					$report['error']['permission'] = $target.$file;
					return $report;
				} else {
					$report['copied'][] = str_replace($base.'/', '', $target.$file);
				}
			}
		}
		return $report;
	}
364819
public function copyDirs($source, $target, $dirs)
    {
        foreach ($dirs as $dir) {
            $this->copyDir($source, $target, $dir);
        }
    }
692381
public function appendTo($target)
    {
        $target_result = $this->getTargetResult($target);

        $target_result->append($this);
        $this->remove();

        return $target_result;
    }