SDL_EnumerateDirectory(3)
π SDL_EnumerateDirectory π
okay bestie, gather round, because this one is from the SDL3 FUNCTIONS collection and it's lowkey iconic β it's called SDL_EnumerateDirectory, and it's literally about listing what's inside a directory, but make it β¨callbackβ¨.
β¨ NAME β¨
SDL_EnumerateDirectory β enumerate a directory through a callback function. yes, a callback. it's giving delegation. it's giving "you handle the entries, i'll handle the walking". π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_filesystem.h>
bool SDL_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata);
like. look at that signature. three little arguments and a bool at the end. immaculate. π
π¦ DESCRIPTION π¦
So here's the tea, fr fr: this function hands you every directory entry through a callback you provide. Your callback gets called once for each directory entry β no cap β and it keeps going until one of two things happens:
- all the results have been provided, or
- the callback returns either
SDL_ENUM_SUCCESSorSDL_ENUM_FAILURE.
That's the whole vibe check. Your callback can pull the plug early by returning one of those enum values. main character energy tbh. π
Now the return value lore: this function returns false if there was a system problem in general, or if a callback returned SDL_ENUM_FAILURE. And a successful return means either a callback returned SDL_ENUM_SUCCESS to halt enumeration, or all directory entries were enumerated. So like, true can mean "we finished everything" or "you told us to stop and we respected that". both are valid. both are slay. π
β οΈ heads up: don't conflate those two success paths in your head, because true genuinely covers both of them. the original says it, so i'm saying it. periodt.
π FUNCTION PARAMETERS π
pathβ the path of the directory to enumerate. the one you're snooping through. respectfully. π΅οΈβοΈcallbackβ a function that is called for each entry in the directory. this is YOUR moment. your time to shine. your little function, called over and over. πuserdataβ a pointer that is passed tocallback. it's the little backpack of stuff you hand over so your callback has context. carry it with you everywhere. π
π RETURN VALUE π
Returns true on success or false on failure; call SDL_GetError() for more information. so if it goes wrong, SDL_GetError() is right there with the receipts. πβ¨
β THREAD SAFETY β
It is safe to call this function from any thread. any thread bestie!! go wild!! π§ go absolutely feral (safely)!! π
π AVAILABILITY π
This function is available since SDL 3.2.0. so if you're on something older... bestie. it's not there. it's simply not there. π upgrade era.
and that's the whole page, mwah π«Ά stay curious, read your callbacks, return your enums, and may your directory enumerations always be true for the right reasons.
this has been a Simple Directmedia Layer production, served to you by SDL 3.4.18 β yes, SDL_EnumerateDirectory(3), that's the one, that's her. take care of her. πβ¨πΈ
π¦ 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