SDL 3.0
|
#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_begin_code.h>
#include <SDL3/SDL_close_code.h>
Go to the source code of this file.
Data Structures | |
struct | SDL_PathInfo |
Macros | |
#define | SDL_GLOB_CASEINSENSITIVE (1 << 0) |
Typedefs | |
typedef int(* | SDL_EnumerateDirectoryCallback) (void *userdata, const char *dirname, const char *fname) |
Functions | |
char * | SDL_GetBasePath (void) |
char * | SDL_GetPrefPath (const char *org, const char *app) |
char * | SDL_GetUserFolder (SDL_Folder folder) |
int | SDL_CreateDirectory (const char *path) |
int | SDL_EnumerateDirectory (const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata) |
int | SDL_RemovePath (const char *path) |
int | SDL_RenamePath (const char *oldpath, const char *newpath) |
int | SDL_GetPathInfo (const char *path, SDL_PathInfo *info) |
char ** | SDL_GlobDirectory (const char *path, const char *pattern, Uint32 flags, int *count) |
Include file for filesystem SDL API functions
Definition in file SDL_filesystem.h.
#define SDL_GLOB_CASEINSENSITIVE (1 << 0) |
Definition at line 334 of file SDL_filesystem.h.
typedef int(* SDL_EnumerateDirectoryCallback) (void *userdata, const char *dirname, const char *fname) |
Definition at line 278 of file SDL_filesystem.h.
enum SDL_Folder |
The type of the OS-provided default folder for a specific purpose.
Note that the Trash folder isn't included here, because trashing files usually involves extra OS-specific functionality to remember the file's original location.
The folders supported per platform are:
Windows | WinRT/UWP | macOS/iOS | tvOS | Unix (XDG) | Haiku | Emscripten | |
---|---|---|---|---|---|---|---|
HOME | X | X | X | X | X | X | |
DESKTOP | X | X | X | X | X | ||
DOCUMENTS | X | X | X | X | |||
DOWNLOADS | Vista+ | X | X | X | |||
MUSIC | X | X | X | X | |||
PICTURES | X | X | X | X | |||
PUBLICSHARE | X | X | |||||
SAVEDGAMES | Vista+ | ||||||
SCREENSHOTS | Vista+ | X | |||||
TEMPLATES | X | X | X | X | |||
VIDEOS | X | X | X* | X |
Note that on macOS/iOS, the Videos folder is called "Movies".
Definition at line 171 of file SDL_filesystem.h.
enum SDL_PathType |
Definition at line 246 of file SDL_filesystem.h.
|
extern |
Create a directory.
path | the path of the directory to create |
|
extern |
Enumerate a directory through a callback function.
This function provides every directory entry through an app-provided callback, called once for each directory entry, until all results have been provided or the callback returns <= 0.
path | the path of the directory to enumerate |
callback | a function that is called for each entry in the directory |
userdata | a pointer that is passed to callback |
|
extern |
Get the directory where the application was run from.
This is not necessarily a fast call, so you should call this once near startup and save the string if you need it.
macOS and iOS Specific Functionality: If the application is in a ".app" bundle, this function returns the Resource directory (e.g. MyApp.app/Contents/Resources/). This behaviour can be overridden by adding a property to the Info.plist file. Adding a string key with the name SDL_FILESYSTEM_BASE_DIR_TYPE with a supported value will change the behaviour.
Supported values for the SDL_FILESYSTEM_BASE_DIR_TYPE property (Given an application in /Applications/SDLApp/MyApp.app):
resource
: bundle resource directory (the default). For example: /Applications/SDLApp/MyApp.app/Contents/Resources
bundle
: the Bundle directory. For example: /Applications/SDLApp/MyApp.app/
parent
: the containing directory of the bundle. For example: /Applications/SDLApp/
Nintendo 3DS Specific Functionality: This function returns "romfs" directory of the application as it is uncommon to store resources outside the executable. As such it is not a writable directory.
The returned path is guaranteed to end with a path separator ('\' on Windows, '/' on most other platforms).
The pointer returned is owned by the caller. Please call SDL_free() on the pointer when done with it.
|
extern |
Get information about a filesystem path.
path | the path to query |
info | a pointer filled in with information about the path, or NULL to check for the existence of a file |
|
extern |
Get the user-and-app-specific path where files can be written.
Get the "pref dir". This is meant to be where users can write personal files (preferences and save games, etc) that are specific to your application. This directory is unique per user, per application.
This function will decide the appropriate location in the native filesystem, create the directory if necessary, and return a string of the absolute path to the directory in UTF-8 encoding.
On Windows, the string might look like:
C:\\Users\\bob\\AppData\\Roaming\\My Company\\My Program Name\\
On Linux, the string might look like:
/home/bob/.local/share/My Program Name/
On macOS, the string might look like:
/Users/bob/Library/Application Support/My Program Name/
You should assume the path returned by this function is the only safe place to write files (and that SDL_GetBasePath(), while it might be writable, or even the parent of the returned path, isn't where you should be writing things).
Both the org and app strings may become part of a directory name, so please follow these rules:
The returned path is guaranteed to end with a path separator ('\' on Windows, '/' on most other platforms).
The pointer returned is owned by the caller. Please call SDL_free() on the pointer when done with it.
org | the name of your organization |
app | the name of your application |
|
extern |
Finds the most suitable user folder for the specified purpose, and returns its path in OS-specific notation.
Many OSes provide certain standard folders for certain purposes, such as storing pictures, music or videos for a certain user. This function gives the path for many of those special locations.
This function is specifically for user folders, which are meant for the user to access and manage. For application-specific folders, meant to hold data for the application to manage, see SDL_GetBasePath() and SDL_GetPrefPath().
Note that the function is expensive, and should be called once at the beginning of the execution and kept for as long as needed.
The returned path is guaranteed to end with a path separator ('\' on Windows, '/' on most other platforms).
The returned value is owned by the caller and should be freed with SDL_free().
If NULL is returned, the error may be obtained with SDL_GetError().
folder | The type of folder to find |
|
extern |
Enumerate a directory tree, filtered by pattern, and return a list.
Files are filtered out if they don't match the string in pattern
, which may contain wildcard characters '*' (match everything) and '?' (match one character). If pattern is NULL, no filtering is done and all results are returned. Subdirectories are permitted, and are specified with a path separator of '/'. Wildcard characters '*' and '?' never match a path separator.
flags
may be set to SDL_GLOB_CASEINSENSITIVE to make the pattern matching case-insensitive.
The returned array is always NULL-terminated, for your iterating convenience, but if count
is non-NULL, on return it will contain the number of items in the array, not counting the NULL terminator.
You must free the returned pointer with SDL_free() when done with it.
path | the path of the directory to enumerate |
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. |
\threadsafety It is safe to call this function from any thread.
|
extern |
Remove a file or an empty directory.
path | the path of the directory to enumerate |
|
extern |
Rename a file or directory.
oldpath | the old path |
newpath | the new path |