PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Ravi Kumar   PHP SPL File Find   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Auxiliary data
Class: PHP SPL File Find
SPL iterator to find files with different criteria
Author: By
Last change: Update of README.md
Date: 6 months ago
Size: 2,161 bytes
 

Contents

Class file image Download

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