Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rcore] Add filtering folders to LoadDirectoryFilesEx()/ScanDirectoryFiles() #4302

Merged

Conversation

foxblock
Copy link
Contributor

@foxblock foxblock commented Sep 1, 2024

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

..\raylib\src\external
..\raylib\src\platforms
..\raylib\src\raudio.c
..\raylib\src\rcore.c
..\raylib\src\rglfw.c
..\raylib\src\rmodels.c
..\raylib\src\rshapes.c
..\raylib\src\rtext.c
..\raylib\src\rtextures.c
..\raylib\src\utils.c

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.

…ursively

Add define FILTER_FOLDER for that purpose
Fix folder names matching filter being added to result
@raysan5 raysan5 changed the title Add filtering folders to LoadDirectoryFilesEx / ScanDirectoryFiles(Recursively) [rcore] Add filtering folders to LoadDirectoryFilesEx()/ScanDirectoryFiles() Sep 2, 2024
src/raylib.h Outdated Show resolved Hide resolved
@raysan5 raysan5 merged commit 16e9317 into raysan5:master Sep 15, 2024
@raysan5
Copy link
Owner

raysan5 commented Sep 15, 2024

@foxblock Thank you very much for the improvement, I will think about the best tag name for directories... but /DIR looks good to me for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants