return whether the item is a directory
@param        $dir
@param null   $rev
@param string $type
@return mixed
190950
public function isDir($dir, $rev=NULL, $type='sandbox')
	{
		$result = $this->metadata($dir, false, true, false, $rev, $type);
		return (bool)$result;
	}
226077
protected final static function readyDir($dir) {
		if(is_file($dir))
			return false;
		
		if (!is_dir(dirname($dir)))
			return mkdir(dirname($dir), 0777, true);
		
		return true;
	}
360473
public function dir(string $type, string $append = ''): string
    {
        return $this->_dir($type, $append);
    }
447815
public function get($directory, $type = self::TYPE_BOTH, $order = self::KEY_NAME, $direction = self::ASC, $limit = null, $fileExtensions = array()) {
        // Get the contents of the dir
        $items     = array();
        $directory = rtrim($directory,'/');

        // Check Dir
        if (!is_dir($directory)) {
            throw new \Exception('Directory does not exist: ' . $directory);
        }

        // Get Raw Listing
        $directoryHandle = opendir($directory);
        while (false !== ($file = readdir($directoryHandle))) {
            // skip anything that starts with a '.' i.e.:('.', '..', or any hidden file)
            if (substr($file, 0, 1) != '.') {
                // Directories
                if (is_dir($directory . '/' . $file) && ($type == self::TYPE_BOTH || $type == self::TYPE_DIR)) {
                    $items[] = array(
                        self::KEY_TYPE => self::TYPE_DIR,
                        self::KEY_NAME => $file,
                        self::KEY_DATE => filemtime($directory.'/'.$file),
                        self::KEY_SIZE => filesize($directory.'/'.$file),
                        self::KEY_EXT  => ''
                    );

                // Files
                } else if (is_file($directory.'/'.$file) && ($type == self::TYPE_BOTH || $type == self::TYPE_FILE)) {
                    if (!count($fileExtensions) || in_array(self::getExtension($file), $fileExtensions)) {
                        $items[] = array(
                            self::KEY_TYPE => self::TYPE_FILE,
                            self::KEY_NAME => $file,
                            self::KEY_DATE => filemtime($directory.'/'.$file),
                            self::KEY_SIZE => filesize($directory.'/'.$file),
                            self::KEY_EXT  => self::getExtension($file)
                        );
                    }
                }
            }

            // Impose Limit, if specified
            if ($limit && count($items) >= $limit) {
                break;
            }
        }

        closedir($directoryHandle);

        // Sorting
        $items = $this->sort($items, $type, $order, $direction);

        // Callbacks
        if ($this->filterCallback) {
            $items = call_user_func($this->filterCallback, $items);
        }

        // Total Size
        $totalSize = 0;
        foreach ($items as $item) {
            $totalSize += $item[self::KEY_SIZE];
        }

        $this->lastSize = $totalSize;
        $this->lastItemCount = count($items);

        return $items;
    }
483926
static function chdir($dir, $callback = null, $argv = array())
    {
        if (!is_dir($dir)) {
            throw new \InvalidArgumentException("$dir does not exist.");
        }

        $cwd = getcwd();
        chdir($dir);

        if (null === $callback) {
            return;
        }

        $returnValue = call_user_func_array($callback, $argv);

        chdir($cwd);
        return $returnValue;
    }
419600
private function _dir(
        string $type,
        string $append = '',
        string $form = ''
    ): string {
        if ('relative' === $form) {
            return \ltrim($append, '/');
        }

        return $this->{'dir'.\ucfirst($type)}.$append;
    }
770128
public function mkdir($dir)
    {
        if (!is_dir($dir)) {
            if (false === @mkdir($dir, $this->mode, true)) {
                $error = error_get_last();
                if (!is_dir($dir)) {
                    if ($error) {
                        throw new IOException(
                            sprintf('Failed to create "%s": %s.', $dir, $error['message']),
                            0,
                            null,
                            $dir
                        );
                    }
                    throw new IOException(sprintf('Failed to create "%s"', $dir), 0, null, $dir);
                }
            }
        }
    }
1065498
public function mkdir(string $directory, int $mode = null): bool {
    if (!empty($directory)) {
      if ($folders = explode(DIRECTORY_SEPARATOR, Path::replaceOSSeparator($directory))) {
        $fullpath = null;
        if (empty($mode)) {
          $mode = AccessMode::MOD_0777;
        }
        foreach ($folders as $folder) {
          if (!empty($folder)) {
            $fullpath .= DIRECTORY_SEPARATOR . $folder;
            $this->createDirectory($fullpath, $mode);
          }
        }
      }
    }
    return file_exists($directory);
  }
644272
public function delDir($dir)
    {
        $dir = $this->checkpath($dir);
        if (@!ftp_rmdir($this->linkid, $dir)) {
            $this->close();
            return false;
        }
        $this->close();
        return true;
    }
575147
private function getDirectories($dir, $directoryName = null)
    {
        $finder = new Finder();
        $finder->directories()->in($dir);

        if (null !== $directoryName) {
            $finder->name($directoryName);
        }

        if (iterator_count($finder) > 0) {
            return iterator_to_array($finder);
        }

        return false;
    }
1214663
public function digipolisMirrorDir($dir, $destination)
    {
        if (!is_dir($dir)) {
            return;
        }
        $task = $this->taskFilesystemStack();
        $task->mkdir($destination);

        $directoryIterator = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
        $recursiveIterator = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::SELF_FIRST);
        foreach ($recursiveIterator as $item) {
            $destinationFile = $destination . DIRECTORY_SEPARATOR . $recursiveIterator->getSubPathName();
            if (file_exists($destinationFile)) {
                continue;
            }
            if (is_link($item)) {
                if ($item->getRealPath() !== false) {
                    $task->symlink($item->getLinkTarget(), $destinationFile);
                }
                continue;
            }
            if ($item->isDir()) {
                $task->mkdir($destinationFile);
                continue;
            }
            $task->copy($item, $destinationFile);
        }
        return $task;
    }
355203
public function rmdirr($dir)
    {
        if ($handle = opendir("$dir")) {
            while ($item = readdir($handle)) {
                if (($item != ".") && ($item != "..")) {
                    if (is_dir("$dir/$item")) {
                        $this->rmdirr("$dir/$item");
                    } else {
                        unlink("$dir/$item");
                    }
                }
            }
            closedir($handle);
            rmdir($dir);
        }
    }
717020
public function isIn($dir) {
		if(!$this->formatPath($dir))
			return false;
		return strpos($this->formatPath($this->src()), $this->formatPath($dir)) === 0;
	}
424870
public static function dir2id($dir, $check = false) {
        if (isset (self::$maps ['dir2id'] [ $dir ])) {
            return self::$maps ['dir2id'] [ $dir ];
        } else if (!$check) {
            return $dir;
        } else if ($check && isset (self::$modules [ $dir ])) {
            return $dir;
        }

        return null;
    }
1016180
protected function scanDir(string $dir): ScanResult
    {
        $fileInfo = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir));
        $files = [];
        foreach ($fileInfo as $pathname => $item) {
            if (!$item->isFile()) {
                continue;
            }

            $files[] = $pathname;
        }

        return $this->scanArray($files);
    }
537313
static function delete_empty_dir($dir)
    {
        $dir = self::makeVirtualDir($dir, false);
        if (is_dir($dir) && sizeof(scandir($dir)) == 2){
            return @rmdir($dir);
        }
        self::deleteVirtualDir($dir);
        return false;
    }
1026588
protected function dirExists($dir)
    {
        if ($this->files->exists($dir)) {

            if ( ! $this->files->isDirectory($dir)) {
                throw new RuntimeException("The given directory [$dir] is not a directory.");
            }

            return true;
        }

        return false;
    }