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 (3 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 170 This week: 2All time: 8,815 This week: 204Up
Version License PHP version Categories
spl-file-find 1.1GNU General Publi...5.4PHP 5, Files and Folders
Description 

Author

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 <contact>
Classes: 6 packages by
Country: India India
Innovation award
Innovation award
Nominee: 2x

Recommendations

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

list files and folders
list files and folders in a directory

Documentation

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>';
	}

Methods

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

extension

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

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

sort

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 );	

limit

This is used to limit the output files.

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

sortByName

Filter files by name

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

sortByNaturalName

Filter files by natural name

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

sortByType

Filter by file or directory

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

sortByAccessedTime

Filter files by last accessed time

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

sortByChangedTime

Filter files by last changed time

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

sortByModifiedTime

Filter files by last modified time

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

onlyFiles

Filter only files

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

onlyDirectories

Filter only directories

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

depth

Filter files by depth level

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

size

Filter files by size

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

License

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 README.md 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  
 100%
Total:170
This week:2
All time:8,815
This week:204Up