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

Recommend this page to a friend!
  Info   Documentation   View files (7)   Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 167 This week: 1All time: 8,649 This week: 255
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.

Recommendations

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

list files and folders
list files and folders in a directory

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: 36
All time rank: 1767107 in India India
Week rank: 136 15 in India India
Innovation award
Innovation award
Nominee: 2x

Details

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  
File Role Description
Iterators (4 files)
Find.php Class Class source
index.php Example Example script
README.md Doc. Auxiliary data

  Files  /  Iterators  
File Role Description
   ExtensionIterator.php Class Class source
   FileSizeIterator.php Class Class source
   FileTypeIterator.php Class Class source
   SortingIterator.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:167
This week:1
All time:8,649
This week:255

For more information send a message to info at phpclasses dot org.