wgirhad/filename-iterator

Glob-like recursive file iterator

v1.0.0 2023-04-09 02:24 UTC

This package is auto-updated.

Last update: 2024-12-09 07:51:52 UTC


README

Glob-like recursive file iterator

Lint Test PHPStan

Usage Examples

Given the following file structure:

src/CoolestClass.php
src/SecondCoolest.php
tests/CoolestClassTest.php
tests/SecondCoolestTest.php
public/static/foo.png
public/static/bar.gif
public/static/images/bar.png
public/static/images/baz.png
public/static/images/fizz.jpeg
public/static/images/buzz.jpg
public/static/images/.peek/aboo.png

Listing all .png images on public/static

<?php

use Wgirhad\FilenameIterator\Iterator as FilenameIterator;

foreach (new FilenameIterator('public/static', '*.png') as $filename) {
    echo "{$filename}\n";
}

// outputs:
// public/static/foo.png
// public/static/images/bar.png
// public/static/images/baz.png
// public/static/images/.peek/aboo.png

Listing all Coolest files

<?php

use Wgirhad\FilenameIterator\Iterator as FilenameIterator;

foreach (new FilenameIterator('*', '*Coolest*.php') as $filename) {
    echo "{$filename}\n";
}

// outputs:
// src/CoolestClass.php
// src/SecondCoolest.php
// tests/CoolestClassTest.php
// tests/SecondCoolestTest.php