SDL_RenamePath(3)

πŸ’– SDL_RenamePath(3) πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, where today's main character is SDL_RenamePath β€” yes, it does exactly what it says on the tin: it renames a file or directory. glow-up for your filesystem, no cap. ✨


🌸 NAME 🌸

SDL_RenamePath β€” rename a file or directory. that's it, that's the whole vibe. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <SDL3/SDL_filesystem.h>

bool SDL_RenamePath(const char *oldpath, const char *newpath);

like… two strings in, one bool out. she's simple, she's efficient, she's iconic. πŸŽ€


✨ DESCRIPTION ✨

okay so here's the tea. if the file sitting at newpath already exists, it's getting replaced. not backed up, not merged, not asked politely β€” replaced. so maybe double-check before you go renaming things onto your precious files, bestie. πŸ™ˆ

also, important: this will not copy files across filesystems/drives/volumes. like, at all. because that would be a much more complicated (and possibly time-consuming) operation, and she is simply not doing all that. 🚫

which is to say β€” and I need you to hear me on this β€” if this function fails, there's a lil workaround you could try for files: SDL_CopyFile() to a temporary file in the same directory as newpath, then SDL_RenamePath() from the temporary file to newpath, and then SDL_RemovePath() on oldpath. that might work. might. πŸ’€

renaming a non-empty directory across filesystems though? dramatically more complex. like, absolutely not, that's a whole other situation, we do not have the bandwidth. 😭


🧚 FUNCTION PARAMETERS 🧚

  • oldpath β€” the old path. the "before" pic. πŸ“Έ
  • newpath β€” the new path. the "after" pic. πŸ’–

πŸ‘‘ RETURN VALUE πŸ‘‘

returns true on success, or false on failure β€” and if it's a false, you gotta call SDL_GetError() for more information, because she will not explain herself unprompted. she's mysterious like that. 🫢


πŸ”₯ THREAD SAFETY πŸ”₯

it is safe to call this function from any thread. go wild, multitask, live your best parallel life. ⭐


🌈 AVAILABILITY 🌈

this function has been available since SDL 3.2.0. a legend from the jump. πŸ‘‘


lowkey reminder: this one replaces stuff at newpath and does not cross filesystems/drives/volumes. be a responsible icon. πŸŽ€

and that's the whole page, bestie!! brought to you by Simple Directmedia Layer in all its SDL 3.4.18 glory β€” mwah, catch you in the next manpage. πŸ“πŸ’œ

πŸ“¦ where this page comes from