Skip to content

Commit

Permalink
REVIEWED: Directory filter tag #4323
Browse files Browse the repository at this point in the history
  • Loading branch information
raysan5 committed Sep 17, 2024
1 parent 186787e commit 627e76c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/rcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ unsigned int __stdcall timeEndPeriod(unsigned int uPeriod);
#define MAX_AUTOMATION_EVENTS 16384 // Maximum number of automation events to record
#endif

#ifndef FILTER_FOLDER
#define FILTER_FOLDER "/DIR" // Filter string used in ScanDirectoryFiles, ScanDirectoryFilesRecursively and LoadDirectoryFilesEx to include directories in the result array
#endif
#ifndef DIRECTORY_FILTER_TAG
#define DIRECTORY_FILTER_TAG "DIR" // Name tag used to request directory inclusion on directory scan
#endif // NOTE: Used in ScanDirectoryFiles(), ScanDirectoryFilesRecursively() and LoadDirectoryFilesEx()

// Flags operation macros
#define FLAG_SET(n, f) ((n) |= (f))
Expand Down Expand Up @@ -3353,7 +3353,7 @@ static void ScanDirectoryFiles(const char *basePath, FilePathList *files, const
}
else
{
if (TextFindIndex(filter, FILTER_FOLDER) >= 0)
if (TextFindIndex(filter, DIRECTORY_FILTER_TAG) >= 0)
{
strcpy(files->paths[files->count], path);
files->count++;
Expand Down Expand Up @@ -3419,7 +3419,7 @@ static void ScanDirectoryFilesRecursively(const char *basePath, FilePathList *fi
}
else
{
if (filter != NULL && TextFindIndex(filter, FILTER_FOLDER) >= 0)
if ((filter != NULL) && (TextFindIndex(filter, DIRECTORY_FILTER_TAG) >= 0))
{
strcpy(files->paths[files->count], path);
files->count++;
Expand Down

2 comments on commit 627e76c

@foxblock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, just a heads up on this change:
This might lead to false-positives in very specific circumstances. i.e. if a file extension like ".DIR" or ".DIRXYZ" was passed as a filter, this code would include directories in the result
That is why I included the slash in the first place, since slashes are not allowed to be part of a filename (or extension) on Mac, Linux and Windows. The other fix for this would be properly splitting the filter string and checking each part individually, but that seemed unnecessarily complicated and slow to me.
This is a very synthetic edge case and might never happen in practice, but I wanted to let you know anyway.

@raysan5
Copy link
Owner Author

@raysan5 raysan5 commented on 627e76c Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I considered that case could happen but DIR seemed more intuitive and easy to remember for users. I think the chances for that to happen are very low and still, it can be customized to something else if some user hit that case.

Please sign in to comment.