Or you will need to use your o/s file systems calls directly.
- For Linux you have to use the POSIX opendir, readdir, closedir which allow you to get all files. It is then up to you to filter the results based on your substring.
- With Win32 it's a little different to what keskiverto says: the FindFirstFile call (corresponding to opendir) can be used with wild card, so you should be able to get the filtered set of files directly. The calls required are FindFirstFile, FindNextFile, FindClose
(There are also corresponding Microsoft CRT calls -- _findfirst, _findnext, and _findclose -- but I've never seen them used.)
Would it be better to use is_directory() rather than exists() on line 25 ?
It could be, depending on the functionality you want. I would rather have an exception thrown if it's fed the name of a file, but I'm good with it just returning an empty list if the directory doesn't exist. Definitely something that should be noted in documentation, though.