[rcore] Add filtering folders to LoadDirectoryFilesEx()
/ScanDirectoryFiles()
#4302
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Right now LoadDirectoryFiles and LoadDirectoryFilesEx only return either all folders and all files (when no filter is passed) or a list of files filtered by file extension.
For use in a file browser (like raygui\examples\custom_file_dialog) it is useful to gather a list of files with a particular extension and also all folders in a location (so the user can navigate further).
This change implements this by adding a FILTER_FOLDER define.
The define can be used as a filter and will match all folders. The contents of the define are chosen as to never match a file extension on Linux and Windows.
So for example you can do
LoadDirectoryFilesEx(%RAYLIB_SRC_DIR%, FILTER_FOLDER";.c", false);
which results in
As a side effect this fixes one "bug" (at least I assume it was not intended behaviour):
LoadDirectoryFiles(Ex) would previously return folders which also matched the file extension. So
LoadDirectoryFilesEx(RAYLIB_SRC_DIR, ".c", false);
would match a folder with a name like "code.c".With this change it does not do that any more (only if FILTER_FOLDER would have been passed as well).
Existing calls to LoadDirectoryFilesEx should not be affected otherwise and return the same results as before.
Btw. I did not see a place to add tests, but I am happy to provide some if needed.