note 111217 added to function.glob

From: Date: Sun, 27 Jan 2013 14:45:11 +0000
Subject: note 111217 added to function.glob
Groups: php.notes 
Request: Send a blank email to php-notes+get-193404@lists.php.net to get a copy of this message
A simple function that find all files by extension an return it by an array. <?php function findFiles($directory, $extensions = array()) { function glob_recursive($directory, &$directories = array()) { foreach(glob($directory, GLOB_ONLYDIR | GLOB_NOSORT) as $folder) { $directories[] = $folder; glob_recursive("{$folder}/*", $directories); } } glob_recursive($directory, $directories); $files = array (); foreach($directories as $directory) { foreach($extensions as $extension) { foreach(glob("{$directory}/*.{$extension}") as $file) { $files[$extension][] = $file; } } } return $files; } var_dump(findFiles("C:", array ( "jpg", "pdf", "png", "html" ))); ?> ---- Server IP: 69.147.83.199 Probable Submitter: 197.225.239.102 ---- Manual Page -- http://php.net/manual/en/function.glob.php Edit -- https://master.php.net/note/edit/111217 Del: integrated -- https://master.php.net/note/delete/111217/integrated Del: useless -- https://master.php.net/note/delete/111217/useless Del: bad code -- https://master.php.net/note/delete/111217/bad+code Del: spam -- https://master.php.net/note/delete/111217/spam Del: non-english -- https://master.php.net/note/delete/111217/non-english Del: in docs -- https://master.php.net/note/delete/111217/in+docs Del: other reasons-- https://master.php.net/note/delete/111217 Reject -- https://master.php.net/note/reject/111217 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193404) next »