Filtering Options
Filter glob results by various criteria.
By File Type
Section titled “By File Type”use Cline\Globby\Globby;
// Only files$files = Globby::find('**/*', onlyFiles: true);
// Only directories$dirs = Globby::find('**/*', onlyDirectories: true);
// Both (default)$all = Globby::find('**/*');By Size
Section titled “By Size”// Files larger than 1KB$large = Globby::find('**/*')->filter( fn($file) => $file->getSize() > 1024);
// Files smaller than 1MB$small = Globby::find('**/*')->filter( fn($file) => $file->getSize() < 1024 * 1024);
// Files between sizes$medium = Globby::find('**/*')->filter( fn($file) => $file->getSize() >= 1024 && $file->getSize() <= 102400);By Date
Section titled “By Date”// Modified in last 24 hours$recent = Globby::find('**/*')->filter( fn($file) => $file->getMTime() > time() - 86400);
// Modified before specific date$old = Globby::find('**/*')->filter( fn($file) => $file->getMTime() < strtotime('2024-01-01'));By Content
Section titled “By Content”// PHP files containing a class$classes = Globby::find('**/*.php')->filter( fn($file) => str_contains(file_get_contents($file), 'class '));
// Files with specific line count$short = Globby::find('**/*.php')->filter(function ($file) { $lines = count(file($file)); return $lines < 100;});Combining Filters
Section titled “Combining Filters”$files = Globby::find('**/*.php') ->filter(fn($f) => $f->getSize() > 0) // Non-empty ->filter(fn($f) => $f->getMTime() > $cutoff) // Recent ->filter(fn($f) => !str_contains($f, 'test')); // Not testsCustom Filters
Section titled “Custom Filters”use Cline\Globby\Filter;
// Create reusable filter$phpFilter = Filter::extension('php') ->and(Filter::minSize(100)) ->and(Filter::modifiedAfter('-1 week'));
$files = Globby::find('**/*', filter: $phpFilter);Sorting Results
Section titled “Sorting Results”$files = Globby::find('**/*.php');
// Sort by name$sorted = $files->sortByName();
// Sort by size$sorted = $files->sortBySize();
// Sort by modification time$sorted = $files->sortByMTime();
// Custom sort$sorted = $files->sort(fn($a, $b) => $a->getSize() <=> $b->getSize());