All Projects → nette → Finder

nette / Finder

Licence: other
🔍 Finder: find files and directories with an intuitive API.

Projects that are alternatives of or similar to Finder

Safe Stream
SafeStream: atomic and safe manipulation with files via native PHP functions.
Stars: ✭ 101 (-86.8%)
Mutual labels:  nette, nette-framework, filesystem
command-line
⌨ Command line options and arguments parser.
Stars: ✭ 35 (-95.42%)
Mutual labels:  nette, nette-framework
Robot Loader
🍀 RobotLoader: high performance and comfortable autoloader that will search and autoload classes within your application.
Stars: ✭ 690 (-9.8%)
Mutual labels:  nette, nette-framework
Di
💎 Flexible, compiled and full-featured Dependency Injection Container with perfectly usable autowiring and support for all new PHP 7 features.
Stars: ✭ 645 (-15.69%)
Mutual labels:  nette, nette-framework
orm
🔥 Well-integrated Doctrine ORM for Nette Framework
Stars: ✭ 51 (-93.33%)
Mutual labels:  nette, nette-framework
playground
📚 Examples, projects, webprojects, skeletons for Nette Framework (@nette) from community members. Included @contributte @apitte @nettrine projects.
Stars: ✭ 23 (-96.99%)
Mutual labels:  nette, nette-framework
psr7-http-message
💫 PSR #7 [HTTP Message Interface] to Nette Framework (@nette)
Stars: ✭ 17 (-97.78%)
Mutual labels:  nette, nette-framework
reCAPTCHA
‼️ Google reCAPTCHA (security) for Nette Framework \ Forms
Stars: ✭ 35 (-95.42%)
Mutual labels:  nette, nette-framework
Tester
Tester: enjoyable unit testing in PHP with code coverage reporter. 🍏🍏🍎🍏
Stars: ✭ 281 (-63.27%)
Mutual labels:  nette, nette-framework
Mail
📧 Handy email creation and transfer library for PHP with both text and MIME-compliant support.
Stars: ✭ 288 (-62.35%)
Mutual labels:  nette, nette-framework
Schema
📐 Validating data structures against a given Schema.
Stars: ✭ 359 (-53.07%)
Mutual labels:  nette, nette-framework
logging
💥 Universal logging support to Tracy / Nette Framework (@nette)
Stars: ✭ 18 (-97.65%)
Mutual labels:  nette, nette-framework
slim-nette-extension
Nette Extension for Slim API micro-framework using middlewares.
Stars: ✭ 17 (-97.78%)
Mutual labels:  nette, nette-framework
codeception
▶️ Integration of Nette Framework to Codeception.
Stars: ✭ 27 (-96.47%)
Mutual labels:  nette, nette-framework
application
✨ Extra contrib to nette/application (@nette)
Stars: ✭ 23 (-96.99%)
Mutual labels:  nette, nette-framework
migrations
🏃 Doctrine Migrations for Nette Framework
Stars: ✭ 36 (-95.29%)
Mutual labels:  nette, nette-framework
Latte
☕ Latte: the intuitive and fast template engine for those who want the most secure PHP sites.
Stars: ✭ 616 (-19.48%)
Mutual labels:  nette, nette-framework
fileupload
🆙 File uploads on steroids for Nette Framework (@nette). Implements blueimp/jquery-file-upload.
Stars: ✭ 28 (-96.34%)
Mutual labels:  nette, nette-framework
NiftyGrid
DataGrid for Nette Framework
Stars: ✭ 34 (-95.56%)
Mutual labels:  nette, nette-framework
Forms
📝 Generating, validating and processing secure forms in PHP. Handy API, fully customizable, server & client side validation and mature design.
Stars: ✭ 272 (-64.44%)
Mutual labels:  nette, nette-framework

Nette Finder: Files Searching

Downloads this Month Tests Coverage Status Latest Stable Version License

Introduction

Nette Finder makes browsing the directory structure really easy.

Documentation can be found on the website.

Support Me

Do you like Nette Finder? Are you looking forward to the new features?

Buy me a coffee

Thank you!

Installation

composer require nette/finder

All examples assume the following class alias is defined:

use Nette\Utils\Finder;

Searching for Files

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

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.

If the directory does not exist, an Nette\UnexpectedValueException is thrown.

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

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

Search by multiple masks and even multiple directories at once:

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

Parameters can also be arrays:

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

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

Searching for Directories

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

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().

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:

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:

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:

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:

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

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

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:

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:

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

Both functions understand the operators >, >=, <, <=, =, !=.

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

$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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].