folders

@param   string  $path
@param   bool    $recursive
@param   boolean $toArray
@param   int     $pathType

@return  \CallbackFilterIterator
327749
public static function dirs($path, $recursive = false, $toArray = false, $pathType = self::PATH_ABSOLUTE)
	{
		/**
		 * Files callback
		 *
		 * @param \SplFileInfo                $current  Current item's value
		 * @param string                      $key      Current item's key
		 * @param \RecursiveDirectoryIterator $iterator Iterator being filtered
		 *
		 * @return boolean   TRUE to accept the current item, FALSE otherwise
		 */
		$callback = function ($current, $key, $iterator) use ($path, $recursive)
		{
			if ($recursive)
			{
				// Ignore self
				if ($iterator->getRealPath() == static::cleanPath($path))
				{
					return false;
				}

				// If set to recursive, every returned folder name will include a dot (.),
				// so we can't using isDot() to detect folder.
				return $iterator->isDir() && ($iterator->getBasename() != '..');
			}
			else
			{
				return $iterator->isDir() && !$iterator->isDot();
			}
		};

		$files = static::findByCallback($path, $callback, $recursive);
		
		if ($toArray) {
		    $files = static::toArray($files, $pathType);
		}
	    
	    return $files;
	}
1355161
public static function files($path, $recursive = false, $pathType = self::PATH_ABSOLUTE)
    {
        $files = [];

        /** @var $file \SplFileInfo */
        foreach (Filesystem::files($path, $recursive) as $file) {
            switch ($pathType) {
                case ($pathType === self::PATH_BASENAME):
                    $name = $file->getBasename();
                    break;

                case ($pathType === static::PATH_RELATIVE):
                    $pathLength = strlen($path);
                    $name = $file->getRealPath();
                    $name = trim(substr($name, $pathLength), DIRECTORY_SEPARATOR);
                    break;

                case ($pathType === static::PATH_ABSOLUTE):
                default:
                    $name = $file->getPathname();
                    break;
            }

            $files[] = $name;
        }

        return $files;
    }
191818
public function listFiles(string $path = '', bool $recursive = false)
    {
        $contents = $this->listContents($path, $recursive);

        $filter = function ($object) {
            return $object['type'] === 'file';
        };

        return \array_values(\array_filter($contents, $filter));
    }
814106
public static function rmWorkingCopy($path, $recursive = true)
    {
        $returnValue = (bool) false;

        
		
		if (is_file($path)) {
			if(preg_match('/^\//', $path)){
				$returnValue = @unlink($path);
			}
		} else if ($recursive) {
			if (is_dir($path)) {
				$iterator = new DirectoryIterator($path);
				foreach ($iterator as $fileinfo) {
					if (!$fileinfo->isDot()) {
						self::rmWorkingCopy($fileinfo->getPathname(), true);
					}
					unset($fileinfo);
				}
				unset($iterator);
				$returnValue = @rmdir($path);
			}
		}
						
        

        return (bool) $returnValue;
    }
5602
public function uasort($callback, $path = '/')
    {
        $value = $this->get($path);
        if (null === $value || !is_array($value)) {
            return;
        }

        uasort($value, $callback);

        $this->set($path, $value);
    }
1098430
public function setPath($path, $recursive = true)
    {
        if (!is_string($path) || preg_match(NodeInterface::MATCH_PATTERN_PATH, $path) !== 1) {
            throw new \InvalidArgumentException('Invalid path "' . $path . '" (a path must be a valid string, be absolute (starting with a slash) and contain only the allowed characters).', 1284369857);
        }

        if ($path === $this->path) {
            return;
        }

        if ($recursive === true) {
            foreach ($this->getChildNodeData() as $childNodeData) {
                $childNodeData->setPath(NodePaths::addNodePathSegment($path, $childNodeData->getName()));
            }
        }

        $pathBeforeChange = $this->path;

        $this->path = $path;
        $this->calculatePathHash();
        $this->parentPath = NodePaths::getParentPath($path);
        $this->calculateParentPathHash();
        $this->depth = NodePaths::getPathDepth($path);

        if ($pathBeforeChange !== null) {
            // this method is called both for changing the path AND in the constructor of Node; so we only want to do
            // these things below if called OUTSIDE a constructor.
            $this->emitNodePathChanged($this);
            $this->addOrUpdate();
        }
    }
1295238
public static function directoryToArray($directory, $recursive = FALSE, $extension = NULL) {
    $array_items = array();
    if ($handle = opendir($directory)) {
      while (FALSE !== ($file = readdir($handle))) {
        if ($file != "." && $file != ".." && (empty($extension) ||
            (!empty($extension) && substr($file, -strlen($extension)) === $extension))
        ) {

          if (is_dir($directory . "/" . $file)) {
            if ($recursive) {
              $array_items = array_merge($array_items, self::directoryToArray($directory . "/" . $file, $recursive));
            }
          }
          else {
            $file = $directory . "/" . $file;
            $array_items[] = preg_replace("/\/\//si", "/", $file);
          }
        }
      }
      closedir($handle);
    }
    return $array_items;
  }
651262
final public function getTreeMetadata($path, $recursive)
    {
        // If $info['truncated'] is `true`, the number of items in the tree array
        // exceeded the github maximum limit. If we need to fetch more items,
        // multiple calls will be needed

        $info = $this->getGitDataApi()->trees()->show(
            $this->settings->getVendor(),
            $this->settings->getPackage(),
            $this->settings->getReference(),
            true //@NOTE: To retrieve all needed date the 'recursive' flag should always be 'true'
        );

        $path = rtrim($path, '/') . '/';

        $treeMetadata = $this->extractMetaDataFromTreeInfo($info[self::KEY_TREE], $path, $recursive);

        $normalizeTreeMetadata = $this->normalizeTreeMetadata($treeMetadata);

        $directoryTimestamp = 0000000000;

        array_walk($normalizeTreeMetadata, function (&$entry) use (&$directoryTimestamp) {
            if ($this->hasKey($entry, self::KEY_TIMESTAMP) === false
                || $entry[self::KEY_TIMESTAMP] === false
            ) {
                $timestamp = $this->getCreatedTimestamp($entry[self::KEY_PATH])['timestamp'];

                $entry[self::KEY_TIMESTAMP] = $timestamp;

                if ($timestamp > $directoryTimestamp) {
                    $directoryTimestamp = $timestamp;
                }
            }
        });

        /* @FIXME: It might be wise to use a filter to find the right entry instead of always using the first entry in the array. */

        $normalizeTreeMetadata[0]['timestamp'] = $directoryTimestamp;

        return $normalizeTreeMetadata;
    }
1220322
public function getMigrationFiles($paths = [], $recursive = true)
    {
        if ($recursive) {
            $paths = $this->getRecursiveFolders($paths);
        }

        $files = parent::getMigrationFiles($paths);

        return $files;
    }
1356222
public function processFilter($toArray = true)
    {
        if ($this->builder) {
            call_user_func($this->builder, $this);
        }

        return $this->filter->execute($toArray);
    }
823439
public function makeDirectory($path, $mode = 0755, $recursive = false, $force = false)
    {
        if ($force) {
            return @mkdir($path, $mode, $recursive);
        }

        return mkdir($path, $mode, $recursive);
    }
628838
public static function createFolder(String $file, Int $permission = 0755, Bool $recursive = true) : Bool
    {
        return Filesystem::createFolder(Info::rpath($file), $permission, $recursive);
    }
577803
public function listDirectory($path, $recursive = false, $withHidden = true)
    {
        $dirs = $this->formatDirsAndFiles($this->laravelFS->directories($path, $recursive));
        $files = $this->formatDirsAndFiles($this->laravelFS->files($path, $recursive));

        $dirsAndFiles = $this->mergeDirsAndFiles($dirs, $files);

        return $this->formatDirsAndFiles($dirsAndFiles);
    }
1073148
public function getAllChildren($recursive = false)
    {
        return $this->appendIterator(
            function ($path) use ($recursive) {
                return $path->getIterator($recursive);
            }
        );
    }
416578
public function scanDir($path, $fileOrDirs = self::ALL, $recursive = true)
    {
        $files = scandir($path);

        $path = $this->stripPathLastDirectorySeparator($path);

        $allFiles = [];
        foreach ($files as $file) {
            if ($file !== '.' && $file !== '..') {
                $pathToScan = $path . DIRECTORY_SEPARATOR . $file;
                if (is_dir($pathToScan)) {
                    if ($recursive) {
                        $moreFiles = $this->scanDir($pathToScan, $fileOrDirs, true);
                        $appendParents = function ($path) use ($file) {
                            return $file . DIRECTORY_SEPARATOR . $path;
                        };
                        $moreFiles = array_map($appendParents, $moreFiles);
                        $allFiles = array_merge($allFiles, $moreFiles);
                    }
                    if ($fileOrDirs & self::DIRS) {
                        $allFiles[] = (string) $file;
                    }
                } else {
                    if ($fileOrDirs & self::FILES) {
                        $allFiles[] = (string) $file;
                    }
                }
            }
        }

        return $allFiles;
    }
227764
public function mkdir($path, $permission = null, $recursive = false)
    {
        $fullPath = $this->concatPaths($path);

        if (file_exists($fullPath) && is_dir($path)) {
            return true;
        }

        $defaultPermissions = $this->getPermissionUtils()->getDefaultPermissions();

        if (!isset($permission)) {
            $permission = (string) $defaultPermissions['dir'];
            $permission = base_convert($permission, 8, 10);
        }

        try {
            $result = mkdir($fullPath, $permission, true);

            if (!empty($defaultPermissions['user'])) {
                $this->getPermissionUtils()->chown($fullPath);
            }

            if (!empty($defaultPermissions['group'])) {
                $this->getPermissionUtils()->chgrp($fullPath);
            }
        } catch (\Exception $e) {
            $GLOBALS['log']->critical('Permission denied: unable to create the folder on the server - '.$fullPath);
        }

        return isset($result) ? $result : false;
    }
318710
public function createDirectory($path, $recursive = false, $mode = null)
    {
        return $this->container()->createDir($path, $recursive, $mode);
    }