I want to list all files at directory and exclude sub directory (newfiles)
i tried to use (if($file != “newfiles”) )
but no thing change
foreach (ListFiles(“/data”) as $key=>$file){
if($file != “newfiles”){
$files=array_pop(explode(‘/’,$file));
$lfile =$files;
}
}
N9ne
June 10, 2014, 8:15am
2
Could you show us what is contained in the ListFiles() function? To debug, perhaps try adding an echo/print into your foreach() loop to see what $file is showing to gain a better idea.
function ListFiles($dir) {
if($dh = opendir($dir)) {
$files = Array();
$inner_files = Array();
while($file = readdir($dh)) {
if($file != "." && $file != ".." && $file[0] != '.') {
if(is_dir($dir . "/" . $file)) {
$inner_files = ListFiles($dir . "/" . $file);
if(is_array($inner_files)) $files = array_merge($files, $inner_files);
} else {
array_push($files, $dir . "/" . $file);
}
}
}
closedir($dh);
return $files;
}
}