Skip to content
Advertisement

Is There A Way To glob() Only Files?

I know that glob can look for all files or only all directories inside a folder :

JavaScript

But I didn’t found something to find only files in a single line efficiently.

JavaScript

Works well but reads directory twice (even if there are some optimizations that make the second browsing quicker).

Advertisement

Answer

I finally found a solution :

JavaScript

But take care, array_filter will preserve numeric keys : use array_values if you need to reindex the array.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement