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 be NULL. 🧚
  • flags β€” SDL_GLOB_* bitflags that affect this search. 🌈
  • count β€” on return, will be set to the number of items in the returned array. can be NULL. ⭐

πŸ’œ 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