2017 © Pedro Peláez
 

library finder

image

nette/finder

  • Thursday, June 28, 2018
  • by david@grudl.com
  • Repository
  • 39 Watchers
  • 222 Stars
  • 3,126,668 Installations
  • PHP
  • 202 Dependents
  • 0 Suggesters
  • 8 Forks
  • 0 Open issues
  • 16 Versions
  • 15 % Grown

The README.md

Downloads this Month Tests Coverage Status Latest Stable Version License, (*1)

Introduction

Nette Finder makes browsing the directory structure really easy., (*2)

Documentation can be found on the website., (*3)

Support Me

Do you like Nette Finder? Are you looking forward to the new features?, (*4)

Buy me a coffee, (*5)

Thank you!, (*6)

Installation

composer require nette/finder

All examples assume the following class alias is defined:, (*7)

use Nette\Utils\Finder;

Searching for Files

How to find all *.txt files in $dir directory and all its subdirectories?, (*8)

foreach (Finder::findFiles('*.txt')->from($dir) as $key => $file) {
    // $key is a string containing absolute filename with path
    // $file is an instance of SplFileInfo
}

The files in the $file variable are instances of the SplFileInfo class., (*9)

If the directory does not exist, an Nette\UnexpectedValueException is thrown., (*10)

And what about searching for files in a directory without subdirectories? Instead of from() use in():, (*11)

Finder::findFiles('*.txt')->in($dir)

Search by multiple masks and even multiple directories at once:, (*12)

Finder::findFiles('*.txt', '*.php')
    ->in($dir1, $dir2) // or from($dir1, $dir2)

Parameters can also be arrays:, (*13)

Finder::findFiles(['*.txt', '*.php'])
    ->in([$dir1, $dir2]) // or from([$dir1, $dir2])

Depth of search can be limited using the limitDepth() method., (*14)

Searching for Directories

In addition to files, it is possible to search for directories using Finder::findDirectories('subdir*')., (*15)

Or to search for files and directories together using Finder::find('*.txt'), the mask in this case only applies to files. When searching recursively with from(), the subdirectory is returned first, followed by the files in it, which can be reversed with childFirst()., (*16)

Mask

The mask does not have to describe only the file name, but also the path. Example: searching for *.jpg files located in a subdirectory starting with imag:, (*17)

Finder::findFiles('imag*/*.jpg')

Thus, the known wildcards * and ? represent any characters except the directory separator /. The double ** represents any characters, including the directory separator:, (*18)

Finder::findFiles('imag**/*.jpg')
// finds also image/subdir/file.jpg

In addition you can use in the mask ranges [...] or negative ranges [!...] known from regular expressions. Searching for *.txt files containing a digit in the name:, (*19)

Finder::findFiles('*[0-9]*.txt')

Excluding

Use exclude() to pass masks that the file must not match. Searching for *.txt files, except those containing 'X' in the name:, (*20)

Finder::findFiles('*.txt')
    ->exclude('*X*')

If exclude() is specified after from(), it applies to crawled subdirectories:, (*21)

Finder::findFiles('*.php')
    ->from($dir)
    ->exclude('temp', '.git')

Filtering

You can also filter the results, for example by file size. Here's how to find files of size between 100 and 200 bytes:, (*22)

Finder::findFiles('*.php')
    ->size('>=', 100)
    ->size('<=', 200)
    ->from($dir)

Filtering by date of last change. Example: searching for files changed in the last two weeks:, (*23)

Finder::findFiles('*.php')
    ->date('>', '- 2 weeks')
    ->from($dir)

Both functions understand the operators >, >=, <, <=, =, !=., (*24)

Here we traverse PHP files with number of lines greater than 1000. As a filter we use a custom callback:, (*25)

$hasMoreThan100Lines = function (SplFileInfo $file): bool {
    return count(file($file->getPathname())) > 1000;
};

Finder::findFiles('*.php')
    ->filter($hasMoreThan100Lines)

Handy, right? You will certainly find a use for Finder in your applications., (*26)

The Versions

28/06 2018

v2.4.x-dev

2.4.9999999.9999999-dev https://nette.org

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

filesystem iterator nette glob

28/06 2018

v2.4.2

2.4.2.0 https://nette.org

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

filesystem iterator nette glob

28/06 2018

dev-master

9999999-dev https://nette.org

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

filesystem iterator nette glob

11/03 2018

dev-standalone

dev-standalone https://nette.org

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

  • php >=7.0

 

The Development Requires

filesystem iterator nette glob

11/07 2017

v2.4.1

2.4.1.0 https://nette.org

Nette Finder: Files Searching

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

02/02 2017

dev-generator

dev-generator https://nette.org

Nette Finder: Files Searching

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

02/02 2017

v3.0.0-RC

3.0.0.0-RC https://nette.org

Nette Finder: Files Searching

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

12/12 2016

v2.3.x-dev

2.3.9999999.9999999-dev https://nette.org

Nette Finder: Files Searching

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

17/05 2016

v2.4.0

2.4.0.0 https://nette.org

Nette Finder: Files Searching

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

06/02 2016

2.2.x-dev

2.2.9999999.9999999-dev https://nette.org

Nette Finder: Files Searching

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

20/10 2015

v2.3.2

2.3.2.0 https://nette.org

Nette Finder: Files Searching

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

19/07 2015

v2.2.2

2.2.2.0 http://nette.org

Nette Finder: Files Searching

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

11/07 2015

v2.3.1

2.3.1.0 http://nette.org

Nette Finder: Files Searching

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

17/02 2015

v2.3.0

2.3.0.0 http://nette.org

Nette Finder: Files Searching

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

20/12 2014

v2.2.1

2.2.1.0 http://nette.org

Nette Finder: Files Searching

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

24/06 2014

v2.2.0

2.2.0.0 http://nette.org

Nette Finder: Files Searching

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires