[rcore] Add filtering folders to LoadDirectoryFilesEx()
/ScanDirectoryFiles()
(#4302)
* Add filtering folders in ScanDirectoryFiles and ScanDirectoryFilesRecursively Add define FILTER_FOLDER for that purpose Fix folder names matching filter being added to result * Move FILTER_FOLDER define to internals of rcore and document option in comment
This commit is contained in:
parent
329b2df4f2
commit
16e9317220
@ -1126,7 +1126,7 @@ RLAPI bool ChangeDirectory(const char *dir); // Change work
|
||||
RLAPI bool IsPathFile(const char *path); // Check if a given path is a file or a directory
|
||||
RLAPI bool IsFileNameValid(const char *fileName); // Check if fileName is valid for the platform/OS
|
||||
RLAPI FilePathList LoadDirectoryFiles(const char *dirPath); // Load directory filepaths
|
||||
RLAPI FilePathList LoadDirectoryFilesEx(const char *basePath, const char *filter, bool scanSubdirs); // Load directory filepaths with extension filtering and recursive directory scan
|
||||
RLAPI FilePathList LoadDirectoryFilesEx(const char *basePath, const char *filter, bool scanSubdirs); // Load directory filepaths with extension filtering and recursive directory scan. Use "/DIR" in the filter string to include directories in the result
|
||||
RLAPI void UnloadDirectoryFiles(FilePathList files); // Unload filepaths
|
||||
RLAPI bool IsFileDropped(void); // Check if a file has been dropped into window
|
||||
RLAPI FilePathList LoadDroppedFiles(void); // Load dropped filepaths
|
||||
|
38
src/rcore.c
38
src/rcore.c
@ -251,6 +251,10 @@ 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
|
||||
|
||||
// Flags operation macros
|
||||
#define FLAG_SET(n, f) ((n) |= (f))
|
||||
#define FLAG_CLEAR(n, f) ((n) &= ~(f))
|
||||
@ -3339,10 +3343,21 @@ static void ScanDirectoryFiles(const char *basePath, FilePathList *files, const
|
||||
|
||||
if (filter != NULL)
|
||||
{
|
||||
if (IsFileExtension(path, filter))
|
||||
if (IsPathFile(path))
|
||||
{
|
||||
strcpy(files->paths[files->count], path);
|
||||
files->count++;
|
||||
if (IsFileExtension(path, filter))
|
||||
{
|
||||
strcpy(files->paths[files->count], path);
|
||||
files->count++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (TextFindIndex(filter, FILTER_FOLDER) >= 0)
|
||||
{
|
||||
strcpy(files->paths[files->count], path);
|
||||
files->count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -3402,7 +3417,22 @@ static void ScanDirectoryFilesRecursively(const char *basePath, FilePathList *fi
|
||||
break;
|
||||
}
|
||||
}
|
||||
else ScanDirectoryFilesRecursively(path, files, filter);
|
||||
else
|
||||
{
|
||||
if (filter != NULL && TextFindIndex(filter, FILTER_FOLDER) >= 0)
|
||||
{
|
||||
strcpy(files->paths[files->count], path);
|
||||
files->count++;
|
||||
}
|
||||
|
||||
if (files->count >= files->capacity)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "FILEIO: Maximum filepath scan capacity reached (%i files)", files->capacity);
|
||||
break;
|
||||
}
|
||||
|
||||
ScanDirectoryFilesRecursively(path, files, filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user