Gets a directory by relative or absolute path,
optionally creates the directory if missing.

@param  string  $path
@param  boolean $createMissing
@return Tarsana\Filesystem\Directory

@throws Tarsana\Filesystem\Exceptions\FilesystemException
6384
public function dir($path, $createMissing = false)
    {
        if (! $this->adapter->isAbsolute($path)) {
            $path = $this->rootPath . $path;
        }
        if (! $createMissing && ! $this->isDir($path, true)) {
            throw new FilesystemException("Cannot find the directory '{$path}'");
        }
        return new Directory($path, $this->adapter);
    }
231709
public function createDir( $path )
    {
        if ( empty( $path ) )
        {
            return false;
        }

        $path = $this->validPath( $path );
        $base = $this->baseUrl . '/' . $path;
        $full = $this->baseDir . '/' . $base;

        if ( ! is_dir( $full ) && ! is_file( $full ) )
        {
            $rights = $this->rights( $path );

            if ( $rights->write && @ mkdir( $full, 0777, true ) )
            {
                return $path;
            }
        }

        return false;
    }
204717
public function makeDirectory($path)
    {
        $this->fs[$path] = $this->newDir();
        $this->fs[$path]->setPath($path);
        return $this->fs[$path];
    }
224587
function imageObject( $createMissing = true )
    {
        if ( $this->ImageObject === null or
             $this->ImageObjectRef === null )
        {
            if ( $createMissing )
            {
                if ( $this->StoredFile != '' )
                {
                    $this->process();
                }
            }
        }
        return $this->ImageObject;
    }
218159
public function assertMissing($path)
    {
        $paths = Arr::wrap($path);

        foreach ($paths as $path) {
            PHPUnit::assertFalse(
                $this->exists($path), "Found unexpected file at path [{$path}]."
            );
        }

        return $this;
    }
809022
public function deleteDirectory(string $path, bool $keepDirectoryStructure = false) : bool
    {
        if (!$this->isDirectory($path)) {
            return false;
        }

        $items = new FilesystemIterator($path);

        foreach ($items as $item) {
            if ($item->isDir()) {
                if (!$this->deleteDirectory($item->getRealPath())) {
                    return false;
                }
            } elseif ($item->isFile()) {
                if (!$this->deleteFile($item->getRealPath())) {
                    return false;
                }
            }
        }

        if (!$keepDirectoryStructure) {
            return rmdir($path);
        }

        return true;
    }
81017
public function subtree($path, string &$name = null, bool $create = false): ?self
    {
        $parts = $this->split($path);

        $dirOrFile = array_shift($parts);
        if (!count($parts)) {
            $name = $dirOrFile;
            $subtree = $this;
        } else {
            $exists = isset($this->subTrees[$dirOrFile]);
            if (!$exists && !$create) {
                $subtree = null;
                $name = null;
            } else {
                if (!$exists && $create) {
                    $this->subTrees[$dirOrFile] = new self();
                }
                $subtree = $this->subTrees[$dirOrFile]->subtree($parts, $name, $create);
            }
        }

        return $subtree;
    }
362236
public function mkdir($path, $permissions = null)
	{
		if ( ! $this->_is_conn())
		{
			return false;
		}

		$result = ftp_mkdir($this->_conn_id, $path);

		if ($result === false)
		{
			if ($this->_debug == true)
			{
				throw new \FtpFileAccessException('Unable to create directory');
			}
			return false;
		}

		// Set file permissions if needed
		if ($permissions !== null)
		{
			$this->chmod($path, (int) $permissions);
		}

		return true;
	}
841684
protected function makeDirectory($path)
    {
        if (! $this->getFiles()->isDirectory(dirname($path))) {
            
            $this->getFiles()->makeDirectory(dirname($path), 0777, true, true);
        }
    }
606279
public function makeDir( $path )
    {
        if ( null === $this->identity )
        {
            return false;
        }

        if ( is_array( $path ) || is_object( $path ) )
        {
            $result = array();

            foreach ( $path as $key => $p )
            {
                $result[$key] = $this->makeDir( $p );
            }

            return $result;
        }

        $path = $this->realPath( $path );
        return $this->createDir( $path );
    }
436558
public function determineFilePath($path, $basePath = null, $makeDir = false)
    {
        $this->logger->debug(sprintf('Search for path: %s with a prefix base path: %s', $path, $basePath));

        if ($this->variable->isEmpty($path)) {
            $this->logger->warning('No Path given to method');
            throw new \Exception('No Path given to method');
        }

        if ($this->variable->isEmpty($basePath)) {
            $basePath = BP;
        }

        // for windows systems
        $path = preg_replace('/\\\\/', '/', $path);

        $path = preg_match('/^\//', $path) || preg_match('/^[a-zA-Z]:\//', $path) ? rtrim($path, '/') :
            rtrim($basePath, '/') . '/' . trim($path, '/');

        $fileCheck = pathinfo($path);
        // Check for last character
        $pathEnding = substr($path, -1);

        if (( ! array_key_exists('extension', $fileCheck) || $this->variable->isEmpty($fileCheck[ 'extension' ])) &&
            $pathEnding != "/" && $pathEnding != "\\"
        ) {
            $path .= '/';
        }

        $dirPath = ! isset($fileCheck[ 'extension' ]) ? $path : dirname($path);

        if ($makeDir && ! is_dir($dirPath)) {
            $this->logger->debug(sprintf('Creating directory with path: %s', $path));

            if ($this->makeDirs($dirPath)) {
                $this->logger->debug(sprintf('Successfully created directory with path: %s', $dirPath));
            } else {
                $this->logger->warning(sprintf('Could not create directory with path: %s', $path));
            }
        }

        $this->logger->debug(sprintf('Created absolute path: %s', $path));

        return $path;
    }
354177
protected function createFolder($folderPath)
    {
        if(!@mkdir($folderPath,0777,true) && !is_dir($folderPath))
        {
            throw new FileSystemException(
                new Phrase('Folder can not be created, but does not exist.')
            );
        }     
        
        return $this;
    }
331799
public static function mkDir($path)
    {
        if (file_exists($path)) {
            return false;
        }

        $umask = umask();
        $res = @mkdir($path, Constants::FILESYSTEM_DIR_PERMISSIONS_DEFAULT, true);
        if ($res === false) {
            throw new RuntimeException('Can not create directory "' . $path . '" - no permissions.');
        }
        umask($umask);

        return $res;
    }
1201174
private function mkdir($path, $mode = 0775, $recursive = true)
    {
        if (is_dir($path)) {
            return true;
        }

        $parentDir = dirname($path);
        // recurse if parent dir does not exist and we are not at the root of the file system.
        if ($recursive && !is_dir($parentDir) && $parentDir !== $path) {
            $this->mkdir($parentDir, $mode, true);
        }

        try {
            if (!mkdir($path, $mode)) {
                return false;
            }
        } catch (\Exception $e) {
            if (!is_dir($path)) {
                throw new Exception(sprintf('Failed to create directory "%s": %s', $path, $e->getMessage()), $e->getCode(), $e);
            }
        }

        try {
            return chmod($path, $mode);
        } catch (\Exception $e) {
            throw new Exception(sprintf('Failed to change permissions for directory "%s": %s', $path, $e->getMessage()), $e->getCode(), $e);
        }
    }
584679
private function makeDirectory($path)
    {
        if ($this->isSFTP()) {
            $created = @$this->ftp->mkdir($path, true);
        } else {
            $created = @ftp_mkdir($this->ftp, $path);
        }
        if (!$created) {
            $this->fail("couldn't make directory {$path}");
        }
        $this->debug("Make directory: {$path}");
    }
342302
public static function create($path, $chmod = 0755)
    {
        $path = Normalize::diskFullPath($path);

        if (self::exist($path)) {
            return false;
        }

        return @mkdir($path, $chmod, true);
    }
351594
public function create($path)
	{
		// If native FTP support is enabled let's use it...
		if (FTP_NATIVE)
		{
			// Turn passive mode on
			if (@ftp_pasv($this->conn, true) === false)
			{
				throw new FilesystemException(__METHOD__ . ': Unable to use passive mode.');
			}

			$buffer = fopen('buffer://tmp', 'r');

			if (@ftp_fput($this->conn, $path, $buffer, FTP_ASCII) === false)
			{
				fclose($buffer);

				throw new FilesystemException(__METHOD__ . 'Bad response.');
			}

			fclose($buffer);

			return true;
		}

		// Start passive mode
		if (!$this->_passive())
		{
			throw new FilesystemException(__METHOD__ . ': Unable to use passive mode.');
		}

		if (!$this->_putCmd('STOR ' . $path, array(150, 125)))
		{
			@ fclose($this->dataconn);

			throw new FilesystemException(
				sprintf('%1$s: Bad response.  Server response: %2$s [Expected: 150 or 125].  Path sent: %3$s', __METHOD__, $this->response, $path)
			);
		}

		// To create a zero byte upload close the data port connection
		fclose($this->dataconn);

		if (!$this->_verifyResponse(226))
		{
			throw new FilesystemException(
				sprintf('%1$s: Transfer failed.  Server response: %2$s [Expected: 226].  Path sent: %3$s', __METHOD__, $this->response, $path)
			);
		}

		return true;
	}