SDL_GlobDirectory(3)
π SDL_GlobDirectory(3) π
okay bestie, welcome to the SDL3 FUNCTIONS section of the manual, and today's main character is SDL_GlobDirectory β she enumerates a directory tree, filters it by pattern, and hands you back a whole list. β¨
πΈ NAME πΈ
SDL_GlobDirectory β enumerate a directory tree, filtered by pattern, and return a list.
π SYNOPSIS π
#include <SDL3/SDL_filesystem.h>
char ** SDL_GlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count);
π¦ DESCRIPTION π¦
so here's the tea, fr fr: files get filtered out if they don't match the string in pattern. and that pattern can have wildcard characters in it, which is lowkey the whole point:
*β match everything π?β match one character
if pattern is NULL, then no filtering happens at all and literally all the results come back. no vibes check, everybody's invited. π
subdirectories are permitted, and you specify them with a path separator of /. and here's the important bit, no cap: the wildcard characters * and ? never match a path separator. so they're not gonna go rogue and eat your slashes.
flags may be set to SDL_GLOB_CASEINSENSITIVE if you want the pattern matching to be case-insensitive. β¨
and the returned array? it's always NULL-terminated, for your iterating convenience, because she's thoughtful like that π«Ά. but if count is non-NULL, then on return it will contain the number of items in the array β and that count does not include the NULL terminator, periodt.
π FUNCTION PARAMETERS π
pathβ the path of the directory to enumerate. that's the one you're going through. πpatternβ the pattern that files in the directory must match. can beNULL. π§flagsβSDL_GLOB_*bitflags that affect this search. πcountβ on return, will be set to the number of items in the returned array. can beNULL. β
π RETURN VALUE π
returns an array of strings on success, or NULL on failure. π if it fails, call SDL_GetError() for more information, she'll tell you what went wrong.
and listen β this is a single allocation, so it should be freed with SDL_free() when it is no longer needed. don't ghost it, actually clean up after yourself bestie π
not me reminding you to free your memory... but yes. free your memory. SDL_free() it. π₯
πΊ THREAD SAFETY πΊ
it is safe to call this function from any thread. multi-threaded queen behavior, we love to see it. π
β¨ AVAILABILITY β¨
this function is available since SDL 3.2.0. so if you're on anything older, sorry babe, she's not there yet. π
π SEE ALSO π
(no cross-references in this one, she stands on her own two feet π«Ά)
and that's the whole page, bestie!! πΈπ¦β¨ this was Simple Directmedia Layer, SDL 3.4.18, and you just read SDL_GlobDirectory(3). go forth and glob responsibly, ily, mwah π
π
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms