-1

I have a problem with script when I scan a folder because array contains sub directories as well:

$location = 'c:\test';
 $files = scandir($location , 1); 

but i would like to scan only files but not folders

Klapsius
  • 3,273
  • 6
  • 33
  • 56
  • if after the provided code you iterate over the files with a foreach loop, you can check if its a directory `if(!is_dir($file)){}` – kscherrer Jan 25 '17 at 14:17

1 Answers1

2

You can use this. It filters out all directories.

$result = array_filter(scandir('/path/to/dir'), function($item) {
    return !is_dir('/path/to/dir/' . $item);
});