framework icon indicating copy to clipboard operation
framework copied to clipboard

[Request] Add extra parameter to FileSystem->directories($directory,$depth)

Open marcvdm opened this issue 13 years ago • 2 comments

Right now on the function you can give only the directory to search for. https://github.com/laravel/framework/blob/master/src/Illuminate/Filesystem/Filesystem.php#L276

But the symfony finder accepts a parameter for depth which is set to 0 https://github.com/laravel/framework/blob/master/src/Illuminate/Filesystem/Filesystem.php#L280

If we could do something like

$FileSystem->directories('/path/to/dir',2);

A use case would be to get all package directories in the vendor map.

marcvdm avatar Nov 10 '13 13:11 marcvdm

Also an option to return the Symfony\Component\Finder\SplFileInfo object would be a great addition.

That way i get all the functions from the SplFileInfo.

$FileSystem->directories('/path/to/dir',true,2);

public function directories($directory,$spl=false,$depth=0)
{
    $directories = array();

    foreach (Finder::create()->in($directory)->directories()->depth($depth) as $dir)
    {
        $directories[] = $spl ? $dir : $dir->getPathname();
    }

    return $directories;
}

marcvdm avatar Nov 10 '13 13:11 marcvdm

Use the Symfony Finder component. It should already be included in your Laravel install.

— Sent from Mailbox for iPhone

On Sun, Nov 10, 2013 at 7:52 AM, Marc van der Meulen [email protected] wrote:

Also an option to return the Symfony\Component\Finder\SplFileInfo object would be a great addition. That way i get all the functions from the SplFileInfo.

$FileSystem->directories('/path/to/dir',true,2);
public function directories($directory,$spl=false,$depth=0)
{
  $directories = array();
  foreach (Finder::create()->in($directory)->directories()->depth($depth) as $dir)
  {
      $directories[] = $spl ? $dir : $dir->getPathname();
  }
  return $directories;
}

Reply to this email directly or view it on GitHub: https://github.com/laravel/framework/issues/2686#issuecomment-28150955

taylorotwell avatar Nov 10 '13 15:11 taylorotwell