PHP Classes

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

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (8 months ago) RSS 2.0 feedNot enough user ratingsTotal: 172 All time: 8,817 This week: 104Up
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 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: 178 Up21 in India India Up
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 (7)  
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 (7)  /  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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:172
This week:0
All time:8,817
This week:104Up