PHP Classes

PHP SPL File Find: SPL iterator to find files with different criteria

Recommend this page to a friend!
  Info   View files Documentation   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (6 months ago) RSS 2.0 feedNot enough user ratingsTotal: 172 All time: 8,813 This week: 104Up
Version License PHP version Categories
spl-file-find 1.1GNU General Publi...5.4PHP 5, Files and Folders


This package implements SPL iterators to find files with different criteria.

It can take a path a directory to traverse to start finding files.

There are additional iterator classes to sort files by name, sort by type, sort by last access time, sort by last change time, to filter files with a given file name extension, filter only files or only directories, and to limit the number of found files, or limit by directory depth or file size.

Innovation Award
PHP Programming Innovation award nominee
July 2014
Number 6

Prize: One book of choice by Packt
Iterator interfaces are useful to traverse sets of information.

This package implements iterator interfaces to find files in a more elegant way.

Manuel Lemos
Picture of Ravi Kumar
  Performance   Level  
Name: Ravi Kumar is available for providing paid consulting. Contact Ravi Kumar .
Classes: 6 packages by
Country: India India
Age: 40
All time rank: 1711101 in India India
Week rank: 228 Up16 in India India Up
Innovation award
Innovation award
Nominee: 2x


Find Large Files
I need to find large files on a server

list files and folders
list files and folders in a directory


SPL Find

This package provides specialized Iterator classes for finding files and directories.

	include_once 'Find.php';

	$path 		=	realpath( 'YOUR_PATH' );

	$find = new Find;
	$files = $find->in( $path );

	foreach( $files as $key => $file) {
		echo '<pre> ' , $key . ' <br> ' , print_r($file, 1), '</pre>';


It uses template and fluent design pattern.

  1. extension
  2. sort
  3. limit
  4. sortByName
  5. sortByNaturalName
  6. sortByType
  7. sortByAccessedTime
  8. sortByChangedTime
  9. sortByModifiedTime
  10. onlyFiles
  11. onlyDirectories
  12. depth
  13. size


This is used to filter the files on the basis of extensions of the file.

	$files = $find->extension(['jpg'])->in( $path );	


This is used to sort the files. <br> const SORT_BY_NAME = 1 <br> const SORT_BY_NAT_NAME = 2

	$files = $find->sort( 2 )->in( $path );	


This is used to limit the output files.

	$files = $find->limit( $offset, $limit )->in( $path );	


Filter files by name

	$files = $find->sortByName()->in( $path );	


Filter files by natural name

	$files = $find->sortByNaturalName()->in( $path );	


Filter by file or directory

	$files = $find->sortByType()->in( $path );	


Filter files by last accessed time

	$files = $find->sortByAccessedTime()->in( $path );	


Filter files by last changed time

	$files = $find->sortByChangedTime()->in( $path );	


Filter files by last modified time

	$files = $find->sortByModifiedTime()->in( $path );	


Filter only files

	$files = $find->onlyFiles()->in( $path );	


Filter only directories

	$files = $find->onlyDirectories()->in( $path );	


Filter files by depth level

	$files = $find->depth(0)->in( $path );	


Filter files by size

	$files = $find->size('>50m')->in( $path );	


Released under the MIT license<br> Copyright (c) 2014 Ravi Kumar

  Files folder image Files  
File Role Description
Files folder imageIterators (4 files)
Plain text file Find.php Class Class source
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file Doc. Auxiliary data

  Files folder image Files  /  Iterators  
File Role Description
  Plain text file ExtensionIterator.php Class Class source
  Plain text file FileSizeIterator.php Class Class source
  Plain text file FileTypeIterator.php Class Class source
  Plain text file SortingIterator.php Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:8,813
This week:104Up