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_SUCCESS or SDL_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 to callback. 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