note 107117 modified in function.scandir by danbrown

From: Date: Mon, 09 Jan 2012 18:19:25 +0000
Subject: note 107117 modified in function.scandir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-185479@lists.php.net to get a copy of this message
I needed to find a way to get the full path of all files in the directory and all subdirectories of a directory. Here's my solution: Recursive functions! <?php function find_all_files($dir) { $root = scandir($dir); foreach($root as $value) { if($value === '.' || $value === '..') {continue;} if(is_file("$dir/$value")) {$result[]="$dir/$value";continue;} foreach(find_all_files("$dir/$value") as $value) { $result[]=$value; } } return $result; } ?> --was-- I needed to find a way to get the full path of all files in the directory and all subdirectories of a directory. Here's my solution: Recursive functions! function find_all_files($dir) { $root = scandir($dir); foreach($root as $value) { if($value === '.' || $value === '..') {continue;} if(is_file("$dir/$value")) {$result[]="$dir/$value";continue;} foreach(find_all_files("$dir/$value") as $value) { $result[]=$value; } } return $result; } http://php.net/manual/en/function.scandir.php

« previous php.notes (#185479) next »